所以我已经为我的合同实现了这个功能
#[payable]
fn send_message(mut self, message: &str, receiver: &str) {当我试图用接近cli来称呼它时
near call v1.messenger.ijelis.testnet send_message '{"message": "test","sender": "iejlis.near"}' --account-id ijelis.testnet
它给了我这个
Scheduling a call: v1.messenger.ijelis.testnet.send_message({"message": "test","sender": "iejlis.near"})
Doing account.functionCall()
Receipt: DDXubobUugwsGnr9GqXxMv7PJqT3YsLjTn14xWML4vx
Failure [v1.messenger.ijelis.testnet]: Error: Contract method is not found
ServerTransactionError: Contract method is not found
at Object.parseResultError (/usr/local/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/rpc_errors.js:31:29)
at Account.signAndSendTransactionV2 (/usr/local/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:160:36)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async scheduleFunctionCall (/usr/local/lib/node_modules/near-cli/commands/call.js:57:38)
at async Object.handler (/usr/local/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
type: 'MethodNotFound',
context: undefined,
index: 0,
transaction_outcome: {
proof: [ [Object] ],
block_hash: 'G4QJ5PPykJWieCyi9P5Rzxu73t1YCKLGKnWL7Z5nUbhd',
id: 'ExJyHwyCpjrFBXGXyr35Y6itkTPVpN1MtE4RnDbo2HBz',
outcome: {
logs: [],
receipt_ids: [Array],
gas_burnt: 2428039504502,
tokens_burnt: '242803950450200000000',
executor_id: 'ijelis.testnet',
status: [Object],
metadata: [Object]
}
}
}我做错什么了?
编辑:我试着使用接近创建应用程序的界面来部署它,一切都很好。
发布于 2021-12-08 04:34:00
看来你没有把合同部署到这个账户上。
像这样检查:
1.有什么东西部署到帐户上了吗?
使用接近CLI快速查看帐户状态(https://docs.near.org/docs/tools/near-cli#near-state)
near state v1.messenger.ijelis.testnet send_message结果
{
amount: '2099882635532834400000000',
locked: '0',
code_hash: 'E8jZ1giWcVrps8PcV75ATauu6gFRkcwjNtKp7NKmipZG',
storage_usage: 268,
storage_paid_at: 0,
block_height: 74201501,
block_hash: '46fdR4oFfEDDuNmLMM8Le6FbKPR3VG5zzNni7u9uE3XQ',
formattedAmount: '2.0998826355328344'
}结论
是的,帐户部署了一些东西,因为code_hash的值不是默认的11111111111111111111111111111111,而是E8jZ1giWcVrps8PcV75ATauu6gFRkcwjNtKp7NKmipZG,它是合同字节代码的base58编码的sha256摘要,是部署到帐户上可用的“合同槽”的数据的指纹。
2.究竟在账户中部署了什么?
使用API查看合同代码:https://docs.near.org/docs/api/rpc/contracts#view-contract-code
http post https://rpc.testnet.near.org jsonrpc=2.0 id=dontcare method=query \
params:='{
"request_type": "view_code",
"finality": "final",
"account_id": "v1.messenger.ijelis.testnet"
}'结果
{
"id": "dontcare",
"jsonrpc": "2.0",
"result": {
"block_hash": "48uCNbhhB9FSg35bJgMDvTpjS5f9n4jrnU4MmMmbHsqj",
"block_height": 74201992,
"code_base64": "AGFzbQEAAAAEBQFwAQEBBQMBABAGGQN/AUGAgMAAC38AQYCAwAALfwBBgIDAAAsHJQMGbWVtb3J5AgAKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwI=",
"hash": "E8jZ1giWcVrps8PcV75ATauu6gFRkcwjNtKp7NKmipZG"
}
}结论
AGFzbQEAAAAEBQFwAQEBBQMBABAGGQN/AUGAgMAAC38AQYCAwAALfwBBgIDAAAsHJQMGbWVtb3J5AgAKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwI=看起来太小了,不适合作为合同,尤其是用锈蚀写成的合同(它们通常比AssemblyScript合同稍大一点)
此base64编码的字符串解码为以下水
(module
(table $T0 1 1 funcref)
(memory $memory (export "memory") 16)
(global $g0 (mut i32) (i32.const 1048576))
(global $__data_end (export "__data_end") i32 (i32.const 1048576))
(global $__heap_base (export "__heap_base") i32 (i32.const 1048576)))所以你认为的合同实际上是没有的。
解决方案
将合同部署到帐户v1.messenger.ijelis.testnet
注:上述WAT分两个步骤生成:
(1)。echo "AGFzbQEAAAAEBQFwAQEBBQMBABAGGQN/AUGAgMAAC38AQYCAwAALfwBBgIDAAAsHJQMGbWVtb3J5AgAKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwI=" | base64 -d > contract.wasm
(2)。将Wasm文件上载到https://webassembly.github.io/wabt/demo/wasm2wat/
https://stackoverflow.com/questions/70267510
复制相似问题