Search code examples
substratepolkadot-jsrust-ink

How can I query contract info with the latest polkadot-js and substrate contracts node?


I've been unable to query my existing contract recently due to Unable to create Enum via index 128, in Alive, Tombstone when using api.query.contracts.contractInfoOf. I get this error both on the command line and in the polkadot-js apps explorer.

These are the steps I took:

  1. Deploy a contract with a salt
  2. Retrieve the contract deployedAddress
  3. Use contractInfoOf
  4. const contractInfo = await api.query.contracts.contractInfoOf(deployedAddress);

I've tried downgrading ink! to 3.0-rc5, 3.0-rc4, 3.0-rc3 and then compiling but it doesn't seem to make any difference. Whenever my contract is built it references rc6 at the top:

{"metadataVersion":"0.1.0","source":{"hash":"0x...","language":"ink! 3.0.0-rc6","compiler":"rustc 1.58.0-nightly",

Which suggests its ignoring my .toml and using rc6 to compile the contract.

I changed my cargo-contract version to 0.14 but that causes polkadot-js to fail at reading the contract abi.

I've tried using the substrate-contracts-node using the latest commit from master and also using the v0.1.0 release. Same error in both cases.

> rustup info

stable-x86_64-unknown-linux-gnu (default)
rustc 1.56.1 (59eed8a2a 2021-11-01)

There are more details in an issue on polkadot-js.

Any pointers on how to get a working setup would be very helpful!


Solution

  • The problem here was substrate-contracts-node using an old version of the metadata.

    I was able to check out the repo before the metadata merge was reverted and build locally (cargo build).

    So checkout 8d91b8e to get the node to work with versions 7.7.1 and 6.6.1 of polkadot-js packages.

    > git checkout 8d91b8e578065a7c06433cbd41ac059bf478a0bd
    > cargo build
    > ./target/debug/substrate-contracts-node --dev --tmp --version
    substrate-contracts-node 0.1.0-8d91b8e-x86_64-linux-gnu