mattlockyer / create-account-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Counter example in Rust

Open in Gitpod!

For Create Account Example Flow

Steps:

  1. generate seed phrase
  2. create account with new accountId and new publicKey
  3. redirects to wallet
  4. on return check the account was created
  5. use the secretKey from the credentials var created in step 1 to create a new account instance
  6. deploy contract to the new account
  7. user is in complete control and has a seed phrase as a recovery method
  8. (optional) keep the new secretKey in localStorage so you can recreate the account instance, or prompt user for seed phrase when they want to access their contract

Description

This contract implements simple counter backed by storage on blockchain. Contract in contract/src/lib.rs provides methods to increment / decrement counter and get it's current value or reset.

Plus and minus buttons increase and decrease value correspondingly. When button L is toggled, a little light turns on, just for fun. RS button is for reset. LE and RE buttons to let the robot wink at you.

To Run

Open in the Gitpod link above or clone the repository.

git clone https://github.com/near-examples/rust-counter

Setup Or skip to Login if in Gitpod

Install dependencies:

yarn

If you don't have Rust installed, complete the following 3 steps:

  1. Install Rustup by running:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

(Taken from official installation guide)

  1. Configure your current shell by running:
source $HOME/.cargo/env
  1. Add wasm target to your toolchain by running:
rustup target add wasm32-unknown-unknown

Next, make sure you have near-cli by running:

near --version

If you need to install near-cli:

npm install near-cli -g

Login

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

In the project root, login with near-cli by following the instructions after this command:

near login

Modify the top of src/config.js, changing the CONTRACT_NAME to be the NEAR account that was just used to log in.


const CONTRACT_NAME = 'YOUR_ACCOUNT_NAME_HERE'; /* TODO: fill this in! */

Start the example!

yarn start

To Test

cd contract
cargo test -- --nocapture

To Explore

  • contract/src/lib.rs for the contract code
  • src/index.html for the front-end HTML
  • src/main.js for the JavaScript front-end code and how to integrate contracts
  • src/test.js for the JS tests for the contract

To Build the Documentation

cd contract
cargo doc --no-deps --open

About

License:MIT License


Languages

Language:HTML 38.8%Language:JavaScript 37.2%Language:Rust 23.1%Language:Dockerfile 0.7%Language:Shell 0.2%