Skip to content

ReCheck-io/gravity-contract-near-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gravity-contract-near-rust

Gravity's Smart Contract for NEAR using Rust

What This Contract Does

Stores unique records for evidence of signing Terms of Service for GRVTY.

Quickstart

Clone this repository locally or open it in GitHub.

git clone git@github.com:ReCheck-io/gravity-contract-near-rust.git

Then follow these steps inside the repo directory:

1. Install Dependencies

Install Rust from the installer script.

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

Set the required target.

rustup target add wasm32-unknown-unknown

2. Build the Contract

Build the contract.

RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release

Run contract tests and verify they pass.

cargo test

3. Deploy the Contract using NEAR CLI

Install NEAR CLI

npm install -g near-cli

By default, it is set for "testnet". For "mainnet" set it like this.

export NEAR_ENV=mainnet

You can verify it to be sure.

echo $NEAR_ENV

Login with your NEAR wallet.

near login

Deploy the contract using a new testnet account.

near dev-deploy ./target/wasm32-unknown-unknown/release/gravity_near.wasm

For mainnet you can create a sub account first.

near create-account SUB-ACCOUNT.YOUR-WALLET-ID.near --masterAccount YOUR-WALLET-ID.near --initialBalance DESIRED-AMMOUNT

And then deploy with the sub account.

near deploy YOUR-NEW-ACCOUNT.near ./target/wasm32-unknown-unknown/release/gravity_near.wasm

Any sub account can be added to your wallet with its private key.

https://wallet.near.org/auto-import-secret-key#YOUR_ACCOUNT_ID/YOUR_PRIVATE_KEY

All account keys are located here.

cd ~/.near-credentials

If any of the steps fails due to low balance use this formula to convert yocto to near.

X yocto / 10^24 = Y NEAR

4. Interact with the Contract using NEAR CLI

Execute change method (you have to be logged in with the same NEAR wallet used for deployment)

near call --accountId YOUR-WALLET-ID.TESTNET ACCOUNT-USED-FOR-DEPLOYMENT signTerms '{"signer_string":"SET_HASH_VALUE","signer_signature_string":"SET_HEX_VALUE","terms_hash_string":"SET_HASH_VALUE"}'

Execute view method (with any logged in wallet)

near view --accountId ANY-WALLET-ID.TESTNET ACCOUNT-USED-FOR-DEPLOYMENT validateSignature '{"signer_string":"SET_HASH_VALUE","terms_hash_string":"SET_HASH_VALUE"}'

5. Function Call Keys

If you don't want to use the Full Access Keys you can create Function Call Keys for the smart contract account.

First generate the new key.

near generate-key

Then add the newly created key to the smart contract account.

near add-key ACCOUNT-USED-FOR-DEPLOYMENT NEWLY_CREATED_PUB_KEY --contract-id ACCOUNT-USED-FOR-DEPLOYMENT

Learn More

  1. Learn more about the contract through its README.
  2. Check our website for more information about us.

About

Gravity Smart Contract for NEAR using Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages