VRC-20合约交互

查询账户vrc-20余额

const VsWeb = require("visionweb");
const HttpProvider = VsWeb.providers.HttpProvider;

const PrivateKey = "your private key";
const FullNode = new HttpProvider("https://vpioneer.infragrid.v.network/");
const SolidityNode = new HttpProvider("https://vpioneer.infragrid.v.network/");
const EventServer = new HttpProvider("https://vpioneer.infragrid.v.network/");

const vsWeb = new VsWeb(FullNode, SolidityNode, EventServer, PrivateKey);
const contractObj = require('./BasicToken.json');
const abi = contractObj.abi;
const bytecode = contractObj.bytecode;


// invoke contract
(async function () {
  // contract address
  const contract = await vsWeb.contract().at("46e2d145ebd0d991f607b4badfb0fa14435a1efe3a");
  // console.log(contract)
  // search balance
  const res = await contract.balanceOf("463a86B966369B5c98F0f7E0B009F4D2aBD4d97162").call();
  console.log(Number(res))

})();

node .\vtest-testbalanceof.js

执行成功可返回账户余额:

788

转账

const VsWeb = require("visionweb");
const HttpProvider = VsWeb.providers.HttpProvider;

const PrivateKey = "your private key";
const FullNode = new HttpProvider("https://vpioneer.infragrid.v.network/");
const SolidityNode = new HttpProvider("https://vpioneer.infragrid.v.network/");
const EventServer = new HttpProvider("https://vpioneer.infragrid.v.network/");

const vsWeb = new VsWeb(FullNode, SolidityNode, EventServer, PrivateKey);
const contractObj = require('./BasicToken.json');
const abi = contractObj.abi;
const bytecode = contractObj.bytecode;


// invoke contract
(async function () {
  // contract address
  const contract = await vsWeb.contract().at("469342bfc79bba12d45e68e9c26dd97076be8ef848");

  let res = await contract.transfer("463a86B966369B5c98F0f7E0B009F4D2aBD4d97162", 100).send({
    feeLimit: 100000000,
    callValue: 0,
    shouldPollResponse: true,
  });
  console.log(res);
})();

转币100VTK

771