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)
添加回答
舉報