Gravity's Smart Contract for NEAR using Rust
Stores unique records for evidence of signing Terms of Service for GRVTY.
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:
Install Rust from the installer script.
curl https://sh.rustup.rs/ -sSf | sh
Set the required target.
rustup target add wasm32-unknown-unknown
Build the contract.
RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release
Run contract tests and verify they pass.
cargo test
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
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"}'
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