rust - 调用合约失败
问题描述
我已将合约部署到 basic-erc20.hash-rush.testnet 帐户。它只是erc20扩展,在 rust 上实现了铸币和可燃扩展。
当我尝试拨打电话时,例如:
near call basic-erc20.hash-rush.testnet inc_allowance '{ "escrow_account_id": "facebook.testnet", "amount": "5" }' --accountId malkevych.testnet
我收到消息:
Scheduling a call: basic-erc20.hash-rush.testnet.inc_allowance({ "escrow_account_id": "facebook.testnet", "amount": "5" })
Receipt: baKLR7NHbUpSRgAr5GVdKXqkJs7PLKS6azHFz183wkN
Failure [basic-erc20.hash-rush.testnet]: Error: Smart contract panicked: panicked at 'The required attached deposit is 33100000000000000000000, but the given attached deposit is is 0', src/lib.rs:462:13
Error: GuestPanic [Error]: Smart contract panicked: panicked at 'The required attached deposit is 33100000000000000000000, but the given attached deposit is is 0', src/lib.rs:462:13
at Object.parseRpcError (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/rpc_errors.js:38:19)
at Account.signAndSendTransaction (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/account.js:144:36)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async scheduleFunctionCall (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/commands/call.js:28:34)
at async Object.handler (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/utils/exit-on-error.js:37:9) {
type: 'GuestPanic',
index: 0,
panic_msg: "panicked at 'The required attached deposit is 33100000000000000000000, but the given attached deposit is is 0', src/lib.rs:462:13"
}
然后我发现我可以使用--gas参数附加气体。所以我再做一个 tx:
near call basic-erc20.hash-rush.testnet inc_allowance '{ "escrow_account_id": "facebook.testnet", "amount": "5" }' --accountId malkevych.testnet --gas 33100000000000000000000
Scheduling a call: basic-erc20.hash-rush.testnet.inc_allowance({ "escrow_account_id": "facebook.testnet", "amount": "5" })
Error: Error: byte array longer than desired length
at assert (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/bn.js/lib/bn.js:6:21)
at BN.toArrayLike (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/bn.js/lib/bn.js:571:5)
at BN.toArray (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/bn.js/lib/bn.js:556:17)
at BinaryWriter.write_u64 (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/serialize.js:86:66)
at serializeField (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/serialize.js:216:41)
at /Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/serialize.js:262:13
at Array.map (<anonymous>)
at serializeStruct (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/serialize.js:261:29)
at serializeField (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/serialize.js:245:13)
at serializeStruct (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/serialize.js:271:17)
所以我试图减少气体量:
near call basic-erc20.hash-rush.testnet inc_allowance '{ "escrow_account_id": "facebook.testnet", "amount": "5" }' --accountId malkevych.testnet --gas 33100000000000000
Scheduling a call: basic-erc20.hash-rush.testnet.inc_allowance({ "escrow_account_id": "facebook.testnet", "amount": "5" })
Error: InvalidTxError: {}
at Object.parseRpcError (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/utils/rpc_errors.js:38:19)
at JsonRpcProvider.sendJsonRpc (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/providers/json-rpc-provider.js:146:40)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Account.signAndSendTransaction (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/node_modules/near-api-js/lib/account.js:115:22)
at async scheduleFunctionCall (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/commands/call.js:28:34)
at async Object.handler (/Users/bohdan_malkevych/.nvm/versions/node/v13.12.0/lib/node_modules/near-shell/utils/exit-on-error.js:37:9) {
type: 'InvalidTxError'
}
再一次,它没有成功。
所有默认测试都运行正常,没有任何错误。提前致谢!
解决方案
您收到的原始错误消息是:
所需的附加存款是33100000000000000000000,但给定的附加存款是0
请注意,这是来自合同本身。您可以看到引发此错误的行:
assert!(
required_deposit <= attached_deposit,
"The required attached deposit is {}, but the given attached deposit is is {}",
required_deposit,
attached_deposit,
);
使用near-cli时,可以--help
在命令后添加,看看可以传递哪些选项。near call --help
返回大量信息;这里的相关位是:
near call <contractName> <methodName> [args]
Options:
...
--gas Max amount of gas this call can use [string] [default: "100000000000000"]
--amount Number of tokens to attach [string] [default: "0"]
您是否尝试过保持gas
默认但设置--amount
为33100000000000000000000
?该命令如下所示:
near call basic-erc20.hash-rush.testnet inc_allowance '{ "escrow_account_id": "facebook.testnet", "amount": "5" }' --accountId malkevych.testnet --amount "33100000000000000000000"
推荐阅读
- c# - .net 核心对 API 和网页控制器的不同错误处理
- python - 在文本文档中搜索字符串
- python - 删除列中的部分值
- javascript - 如何在 JavaScript 中停用 beforeunload 事件监听器
- html - 为什么 css 类在 ion-toolbar 中不起作用?
- azure - 为什么我收到“New-AzSqlDatabaseImport:未找到:找不到实体以调用导入”
- python - keras 只会给出 0.5001 的准确度
- node.js - 解决快递请求中的 UnhandledPromiseRejectionWarning
- constraint-programming - 在约束中使用 IntVar 作为 IntVar[] 数组的索引
- perl - 从一个 Excel 文件复制到另一个文件时无法保留格式