Method not found when update contract in NEAR

329 Views Asked by At

I have seen strange behavior when updating contracts in near(using rust)

I usually launch 1 first contract as templates, following the usual commands:

$ cargo new rust-myproject
cargo test -- --nocapture
cargo build --target wasm32-unknown-unknown --release
near deploy --wasmFile target/wasm32-unknown-unknown/release/myproject.wasm --accountId myaccount.testnet

near call myaccount.testnet mymethod --accountId myaccount.testnet

So far so good, the problem comes when I want to add methods and I have to update the contract. When I update it, the new methods are not there, but I see in the near explorer how it is that if the contract was updated, it seems that the new contract is not being taken into account.

enter image description here

Sometimes it updates other times it doesn't update at all.

How can you be sure that the contract is the new one? I am relying on the explorer but is there another way?

Obviously when I try to call i received "Method not found"

type: 'MethodNotFound',
  context: undefined,
  index: 0,
  transaction_outcome: {
    proof: [ [Object], [Object] ],
    block_hash: '57ULC9DaU63hbQGPCvGVvvLh7TPVhrXSZfAqcwyvoWWz',
    id: '5EGfWdg2qWXvddT4v2JiyvzZ7Esdp5Qy4MJoo3qJvTHu',
    outcome: {
      logs: [],
      receipt_ids: [Array],
      gas_burnt: 2427950067142,
      tokens_burnt: '242795006714200000000',
      executor_id: 'josedlujan.testnet',
      status: [Object],
      metadata: [Object]
1

There are 1 best solutions below

3
owl On

I think every contract is unique. You cannot actually update the existing contract.

What you can do is using:

  1. use dev-deploy to generate a new contract id each time
  2. use your currrent account(main account) create a sub-account(sub-account) can treat as a user account/ contract .
  3. Then you use this sub-acc (contract) to deploy it.

near create-account CONTRACT_NAME.ACCOUNT_ID --masterAcount ACCOUNT_ID --initialBalance 10

near deploy --wasmFile target/wasm32-unknown-unknown/release/key_value_storage.wasm --accountId CONTRACT_ID

You can reference this article.

https://learn.figment.io/tutorials/write-and-deploy-a-smart-contract-on-near

(I also just start to learn the Near Protocol Smart Contract. Please correct me if I am wrong.)