gpt4 book ai didi

rust - 调用合约失败

转载 作者:行者123 更新时间:2023-12-03 11:41:33 26 4
gpt4 key购买 nike

我已将合约部署到 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"
}
然后我发现我可以使用 附加气体--煤气参数。所以我再做一个 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'
}
再一次,它没有成功。
所有默认测试都运行正常,没有任何错误。提前致谢!

最佳答案

您收到的原始错误消息是:

The required attached deposit is 33100000000000000000000, but the given attached deposit is is 0


请注意,这是来自契约(Contract)本身。可以看 the lines that throw this error :
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默认设置 --amount33100000000000000000000 ?该命令如下所示:
 near call basic-erc20.hash-rush.testnet inc_allowance '{ "escrow_account_id": "facebook.testnet", "amount": "5" }' --accountId malkevych.testnet --amount "33100000000000000000000"

关于rust - 调用合约失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64451837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com