1 回答

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
您像往常一樣設(shè)置合同:
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"})
然而,當(dāng)你想附加一些 NEAR 代幣或增加 gas 津貼時(shí),你需要在參數(shù)后指定可選的位置參數(shù):
await?contract.changeMethodName(args:?object,?gas:?BN,?amount:?BN)
筆記:
BN是大數(shù)表示
默認(rèn)的 gas 限額是 300 Tgas [300 * 10^12 gas]
數(shù)量在 yoctoNEAR 中指定(1 NEAR 是 10^24 yoctoNEAR)
例如:
const ONE_NEAR = new BN("1000000000000000000000000")
await contract.createCorgi({"id": "corgi_xxx"}, new BN("3000000000000"), ONE_NEAR)
添加回答
舉報(bào)