rust 调用合同失败

mbskvtky  于 2023-06-23  发布在  其他
关注(0)|答案(2)|浏览(146)

我将我的合约部署到basic-erc 20.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**参数来连接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'
}

而且它再次没有成功。
所有默认测试运行正常,没有任何错误。先谢谢你了!

unhi4e5o

unhi4e5o1#

您收到的原始错误消息是:
要求的附加存款是3310000000000000000000000000000,但给出的附加存款是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"
zrfyljdw

zrfyljdw2#

使用depositYocto为我工作。
您可以像这样重试该命令:

near call basic-erc20.hash-rush.testnet inc_allowance '{ "escrow_account_id": "facebook.testnet", "amount": "5" }' --accountId malkevych.testnet --depositYocto "33100000000000000000000"

相关问题