Reputation:
So I have this function implemented for my Contract
#[payable]
fn send_message(mut self, message: &str, receiver: &str) {
When I try to call it using near-cli
near call v1.messenger.ijelis.testnet send_message '{"message": "test","sender": "iejlis.near"}' --account-id ijelis.testnet
It gives me out this
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]
}
}
}
What Am I doing wrong?
EDIT: I tried to deploy it using near-create-app interface, and everything worked fine.
Upvotes: 3
Views: 1093
Reputation: 11
Ensure you use #[near_bindgen]
derive macro on your contract impl block to make pub contract methods visible.
Upvotes: 0
Reputation: 1591
seems you did not deploy the contract to this account.
check like this:
Use NEAR CLI to quickly view account state (https://docs.near.org/docs/tools/near-cli#near-state)
near state v1.messenger.ijelis.testnet send_message
Result
{
amount: '2099882635532834400000000',
locked: '0',
code_hash: 'E8jZ1giWcVrps8PcV75ATauu6gFRkcwjNtKp7NKmipZG',
storage_usage: 268,
storage_paid_at: 0,
block_height: 74201501,
block_hash: '46fdR4oFfEDDuNmLMM8Le6FbKPR3VG5zzNni7u9uE3XQ',
formattedAmount: '2.0998826355328344'
}
Conclusion
Yes, the account has something deployed to it because the value of code_hash
is not the default 11111111111111111111111111111111
but E8jZ1giWcVrps8PcV75ATauu6gFRkcwjNtKp7NKmipZG
which is a base58 encoded sha256 digest of the contract byte code, a fingerprint of the data deployed to the available "contract slot" on the account
Use the API to view contract code: 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"
}'
Result
{
"id": "dontcare",
"jsonrpc": "2.0",
"result": {
"block_hash": "48uCNbhhB9FSg35bJgMDvTpjS5f9n4jrnU4MmMmbHsqj",
"block_height": 74201992,
"code_base64": "AGFzbQEAAAAEBQFwAQEBBQMBABAGGQN/AUGAgMAAC38AQYCAwAALfwBBgIDAAAsHJQMGbWVtb3J5AgAKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwI=",
"hash": "E8jZ1giWcVrps8PcV75ATauu6gFRkcwjNtKp7NKmipZG"
}
}
Conclusion
AGFzbQEAAAAEBQFwAQEBBQMBABAGGQN/AUGAgMAAC38AQYCAwAALfwBBgIDAAAsHJQMGbWVtb3J5AgAKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwI=
looks way too small to be a contract, especially one written in Rust (they're usually a little bigger than AssemblyScript contracts)
This base64 encoded string decodes to the following WAT
(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)))
So the contract you think is there is not actually there.
Deploy the contract to the account v1.messenger.ijelis.testnet
Note: the WAT above was generated in two steps:
(1). echo "AGFzbQEAAAAEBQFwAQEBBQMBABAGGQN/AUGAgMAAC38AQYCAwAALfwBBgIDAAAsHJQMGbWVtb3J5AgAKX19kYXRhX2VuZAMBC19faGVhcF9iYXNlAwI=" | base64 -d > contract.wasm
(2). upload Wasm file to https://webassembly.github.io/wabt/demo/wasm2wat/
Upvotes: 2