Giter VIP home page Giter VIP logo

rust-status-message's Introduction

Status Message

Open in Gitpod

This smart contract saves and records the status messages of NEAR accounts that call it.

Windows users: please visit the Windows-specific README file.

Prerequisites

Ensure near-cli is installed by running:

near --version

If needed, install near-cli:

npm install near-cli -g

Ensure Rust is installed by running:

rustc --version

If needed, install Rust:

curl https://sh.rustup.rs -sSf | sh

Install dependencies

npm install

Quick Start

To run this project locally:

  1. Prerequisites: Make sure you have Node.js โ‰ฅ 12 installed (https://nodejs.org), then use it to install yarn: npm install --global yarn (or just npm i -g yarn)
  2. Run the local development server: yarn && yarn dev (see package.json for a full list of scripts you can run with yarn) Now you'll have a local development environment backed by the NEAR TestNet! Running yarn dev will tell you the URL you can visit in your browser to see the app.

Building this contract

To make the build process compatible with multiple operating systems, the build process exists as a script in package.json. There are a number of special flags used to compile the smart contract into the wasm file. Run this command to build and place the wasm file in the res directory:

npm run build

Note: Instead of npm, users of yarn may run:

yarn build

Important

If you encounter an error similar to:

note: the wasm32-unknown-unknown target may not be installed

Then run:

rustup target add wasm32-unknown-unknown

Using this contract

Web app

Deploy the smart contract to a specific account created with the NEAR Wallet. Then interact with the smart contract using near-api-js on the frontend.

If you do not have a NEAR account, please create one with NEAR Wallet.

Make sure you have credentials saved locally for the account you want to deploy the contract to. To perform this run the following near-cli command:

near login

Deploy the contract to your NEAR account:

near deploy --wasmFile res/status_message.wasm --accountId YOUR_ACCOUNT_NAME

Build the frontend:

npm start

If all is successful the app should be live at localhost:1234!

Quickest deploy

Build and deploy this smart contract to an development account. This development account will be created automatically and is not intended to be permanent. Please see the "Standard deploy" section for creating a more personalized account to deploy to.

near dev-deploy --wasmFile res/status_message.wasm --helperUrl https://near-contract-helper.onrender.com

Behind the scenes, this is creating an account and deploying a contract to it. On the console, notice a message like:

Done deploying to dev-1234567890123

In this instance, the account is dev-1234567890123. A file has been created containing the key to the account, located at neardev/dev-account. To make the next few steps easier, we're going to set an environment variable containing this development account id and use that when copy/pasting commands. Run this command to the environment variable:

source neardev/dev-account.env

You can tell if the environment variable is set correctly if your command line prints the account name after this command:

echo $CONTRACT_NAME

The next command will call the contract's set_status method:

near call $CONTRACT_NAME set_status '{"message": "aloha!"}' --accountId $CONTRACT_NAME

To retrieve the message from the contract, call get_status with the following:

near view $CONTRACT_NAME get_status '{"account_id": "'$CONTRACT_NAME'"}'

Standard deploy

In this option, the smart contract will get deployed to a specific account created with the NEAR Wallet.

If you do not have a NEAR account, please create one with NEAR Wallet.

Make sure you have credentials saved locally for the account you want to deploy the contract to. To perform this run the following near-cli command:

near login

Deploy the contract:

near deploy --wasmFile res/status_message.wasm --accountId YOUR_ACCOUNT_NAME

Set a status for your account:

near call YOUR_ACCOUNT_NAME set_status '{"message": "aloha friend"}' --accountId YOUR_ACCOUNT_NAME

Get the status:

near view YOUR_ACCOUNT_NAME get_status '{"account_id": "YOUR_ACCOUNT_NAME"}'

Note that these status messages are stored per account in a HashMap. See src/lib.rs for the code. We can try the same steps with another account to verify. Note: we're adding NEW_ACCOUNT_NAME for the next couple steps.

There are two ways to create a new account:

  • the NEAR Wallet (as we did before)
  • near create_account NEW_ACCOUNT_NAME --masterAccount YOUR_ACCOUNT_NAME

Now call the contract on the first account (where it's deployed):

near call YOUR_ACCOUNT_NAME set_status '{"message": "bonjour"}' --accountId NEW_ACCOUNT_NAME
near view YOUR_ACCOUNT_NAME get_status '{"account_id": "NEW_ACCOUNT_NAME"}'

Returns bonjour.

Make sure the original status remains:

near view YOUR_ACCOUNT_NAME get_status '{"account_id": "YOUR_ACCOUNT_NAME"}'

Testing

To test run:

cargo test --package status-message -- --nocapture

rust-status-message's People

Contributors

dependabot-preview[bot] avatar mikedotexe avatar janedegtiareva avatar idea404 avatar mosesfinlay avatar chadoh avatar thisisjoshford avatar adsick avatar suraneti avatar vgrichina avatar mehtaphysical avatar frol avatar benkurrek avatar ailisp avatar tarasenkofirelabs avatar dependabot[bot] avatar

Stargazers

stewshka avatar Siphamandla Mjoli avatar otnm avatar  avatar Duc-Viet Hoang avatar Lucmarix Song avatar Cao Trong Tin avatar Vladimir Podolyan avatar radioevrazia avatar Andrew Weisbeck avatar Pritam Dhara avatar 0xrinegade avatar Mark Shellrude avatar  avatar zhangbo avatar  avatar Rahul S. Poudel avatar Evgeniy Abramov avatar An avatar 0xQuantumKing avatar xiyao avatar Carlos Guimaraes avatar Sudipto Bhukta (Preferred name: Sean) avatar Nikhil avatar Maxvyr avatar Quan Tran avatar Yuriy Dybskiy avatar Hassan ali avatar Sean Wilson avatar Steve Yu avatar Abhishek Uniyal avatar Michael  Martin avatar 3.141592653589793238462643383279 avatar Juan Felix avatar  avatar  avatar luckychacha avatar Obi avatar  avatar  avatar Enki avatar antain avatar GS Chavan avatar Reed HHW avatar Loris Ciprin avatar dp avatar

Watchers

 avatar  avatar James Cloos avatar  avatar

rust-status-message's Issues

Add a meaningful message for log usage.

We currently have, e.g. env::log(b"A");
this is a good example of usage of log function, but it would be better to add a readable message so that it's more clear what the parameter is.

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

Automerging is not enabled for this account. You can enable it from the [account settings](https://app.dependabot.com/accounts/near-examples/settings) screen in your Dependabot dashboard.

Please update the config file to conform with Dependabot's specification using our docs and online validator.

Gitpod not configured correctly?

I tried out this repo's gitpod but it looks like maybe the environment is not set up correctly. The readme says that the following should echo the account but that variable is not set:

echo $CONTRACT_NAME

Also, it looks like the near tool is not installed:

gitpod /workspace/rust-status-message $ near
bash: near: command not found

Call method is failing.

Hi,
I tried to run this contract using std deploy method, But ended up with errors for call method.
(Tried using quick deploy, it worked fine)
Screenshot from 2020-05-21 13-37-00

Please help me
Thanks

Create simple frontend for example

This example currently has instructions in the README file. Let's get a frontend going.

A lot of the styling and theme can be borrowed from the Guest Book example. See live at: https://near-examples.github.io/guest-book

Note: the status message is not a "status message" in terms of Twitter where there are multiple statuses. Instead, each user only has one status for them. Here's an idea of what the frontend should look like:

Screen Shot 2021-07-27 at 3 23 36 PM

Acceptance criteria:

If there are any questions about the proper colors to use (although probably not because this can just be borrowed from Guest Book wholesale) you may check out the branding at https://near.org/brand

Build Failure

Noticed the following issues:

  1. Rust is not listed as a pre-requisite for this project. The build fails if rust is not installed.
  2. After installing Rust and running the build (yarn build) again I got the following error and the build failed:
    image

just run `near deploy` cmd can't generate `neardev` folder

according to README.md, can't generate neardev folder, run npm start echo some errors:

Error: Failed to find .env file at path: ./neardev/dev-account.env
    at getEnvFile (/Users/qiao/projects/rust-status-message/node_modules/env-cmd/dist/get-env-vars.js:40:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `npm run build && npm run build:web && env-cmd -f ./neardev/dev-account.env parcel ./frontend/index.html`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/qiao/.npm/_logs/2021-09-12T06_33_23_203Z-debug.log

solution:

run deploy:dev, all is successful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.