首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决智能契约的错误?

如何解决智能契约的错误?
EN

Stack Overflow用户
提问于 2021-06-13 00:25:44
回答 1查看 153关注 0票数 2

我第一次尝试叫。请告诉我如何解决以下错误。

  1. 我在帐户附近创建了Testnet。
  2. 我用这个例子"https://github.com/near-examples/rust-counter/blob/master/contract/src/lib.rs"“编译了”计数器“契约。
  3. 我已使用“近cli”将此合同部署到testnet,并取得了成功。
  4. 我称之为近cli的"veiw函数“,错误返回。
代码语言:javascript
复制
% 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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-13 06:37:29

Counter不是一个有效的帐户id.帐户内不允许大写字母-id。)。您需要传递正确的account-id

我希望您的帐户id是某种形式的takahashi.testnetdev-1623565709996-68004511819798 (如果契约是使用near dev-deploy命令部署的)。

这就是如何使用dev-deploy部署到testnet,以及如何使用near-cli调用视图函数。

代码语言:javascript
复制
❯ 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

如果您使用的是mainnet网络(而不是testnet),则需要通过设置环境变量让近-cli知道这一点:

代码语言:javascript
复制
❯ export NEAR_ENV=mainnet
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67953918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档