1 回答
TA贡献1779条经验 获得超6个赞
您像往常一样设置合同:
const contract = await new nearlib.Contract(
walletConnection.account(),
nearConfig.contractName,
{
// View methods are read only. They don't modify the state, but usually return some value.
viewMethods: ["getCorgi", "getCorgisList", "displayGolbalCorgis"],
// Change methods can modify the state. But you don't receive the returned value when called.
changeMethods: ["transferCorgi", "createCorgi", "deleteCorgi"],
// Sender is the account ID to initialize transactions.
sender: walletConnection.getAccountId(),
}
);
通常,您将 change 方法称为:
await contract.transferCorgi({"receiver": "frol.near", "id": "corgi_xxx", "message": "hello"})
然而,当你想附加一些 NEAR 代币或增加 gas 津贴时,你需要在参数后指定可选的位置参数:
await contract.changeMethodName(args: object, gas: BN, amount: BN)
笔记:
BN是大数表示
默认的 gas 限额是 300 Tgas [300 * 10^12 gas]
数量在 yoctoNEAR 中指定(1 NEAR 是 10^24 yoctoNEAR)
例如:
const ONE_NEAR = new BN("1000000000000000000000000")
await contract.createCorgi({"id": "corgi_xxx"}, new BN("3000000000000"), ONE_NEAR)
添加回答
举报