gpt4 book ai didi

smartcontracts - 如何解决智能合约的错误?

转载 作者:行者123 更新时间:2023-12-04 07:30:40 27 4
gpt4 key购买 nike

我第一次尝试通过 NEAR 协议(protocol)调用智能合约。
请告诉我如何解决以下错误。

  • 我已经创建了 Testnet NEAR 帐户。
  • 我使用此示例“https://github.com/near-examples/rust-counter/blob/master/contract/src/lib.rs”编译了“计数器”契约(Contract)。
  • 我已经使用“near cli”将该合约部署到了测试网,并且已经成功。
  • 我调用了近cli的“veiw函数”,错误返回。
  • % near view Counter get_num '{}'
    View call: Counter.get_num({})
    An error occured
    Error: [-32000] Server error: Account ID Counter is invalid
    at /Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:322:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Object.exponentialBackoff [as default] (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24)
    at async JsonRpcProvider.sendJsonRpc (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:297:24)
    at async JsonRpcProvider.query (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:109:22)
    at async Account.viewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:356:24)
    at async exports.callViewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/index.js:75:48)
    at async Object.handler (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9)
    TypedError: [-32000] Server error: Account ID Counter is invalid
    at /Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:322:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Object.exponentialBackoff [as default] (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24)
    at async JsonRpcProvider.sendJsonRpc (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:297:24)
    at async JsonRpcProvider.query (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:109:22)
    at async Account.viewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:356:24)
    at async exports.callViewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/index.js:75:48)
    at async Object.handler (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
    type: 'UntypedError',
    context: undefined
    }

    最佳答案

    Counter不是有效的帐户 ID。 Uppercase letters in accounts-id are not allowed )。您需要通过正确的account-id .
    我希望您的帐户 ID 格式为 takahashi.testnet dev-1623565709996-68004511819798 (如果合约是使用 near dev-deploy 命令部署的)。
    这是您可以使用 dev-deploy 部署到测试网的方式, 并使用 near-cli 调用 View 函数:

    ❯ near --version
    2.0.2

    ❯ near dev-deploy out/main.wasm
    Starting deployment. Account id: dev-1623565709996-68004511819798, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: out/main.wasm
    Transaction Id 5eTde2dUw5QTA8hbpWvAw4ABary64Tsnj9FzBCPS9Ne
    Done deploying to dev-1623565709996-68004511819798

    ❯ near view dev-1623565709996-68004511819798 get_num '{}'
    View call: dev-1623565709996-68004511819798.get_num({})
    0
    如果您使用的是主网网络(而不是测试网),则需要通过设置环境变量让 near-cli 知道这一点:
    ❯ export NEAR_ENV=mainnet

    关于smartcontracts - 如何解决智能合约的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67953918/

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