Integrating with NEAR Protocol

(20 nL)
4 min read
To Share and +4 nLEARNs

A write up of our NEAR integration journey

  • Sharded
  • WASM Smart Contracts
git clone https://github.com/near-examples/counter
yarn

We only care about these 2 folders and 1 file

https://github.com/near/near-sdk-as/tree/master/sdk-core/assembly/collections
  • persistentMap — set/get
  • persistentUnorderedMap — set/get/query/length
let balance = myPersistentMap.get("myacc.near", u128.Zero)!
npm install near-cli -g
yarn build
ACC1=$(near dev-deploy out/main.wasm | sed 's/.*id: \(.*\), node.*/\1/' | head -n 1)
near view --accountId $ACC1 $ACC1 getCounter '{}'
View call: dev-1623290109414-64922580028342.getCounter({})
0
near call --accountId $ACC1 $ACC1 incrementCounter '{"value": 1}'
node << EOF
const fetch = require('node-fetch');
async function go() {
  const args_base64 = Buffer.from('{}').toString('base64')
  const params = {account_id: "zodtv.near", method_name: "mint_status", 
    request_type: "call_function", finality: "final", "args_base64": args_base64}
  const json_args = {jsonrpc: "2.0", id: "1", method: "query", params: params}

  const fetch_args = {
    method: "POST",
    body: JSON.stringify(json_args),
    headers: {
      "Content-Type": "application/json"
    }
  }
  const response = await fetch("https://rpc.mainnet.near.org", fetch_args);
  const {result} = await response.json();

  const mint_status = JSON.parse((new TextDecoder()).decode(new Uint8Array(result.result)))
  console.log(mint_status)
}
go()
EOF
{
  "total_minted": "3120000000000000000000000000",
  "level": "0",
  "near_price": "3000000000000000000000000",
  "zod_price": "10000000000000000000000"
}
Generate comment with AI 2 nL
518

Leave a Comment


To leave a comment you should to:


Scroll to Top
Report a bug👀