2

My code:

const main = async() => {

    //Get wasm 
    // This file wasm I already build through "cargo contract build"
    let wasm = fs.readFileSync("../../res/incrementer.wasm");
    
    // API creation for connection to the chain
    const wsProvider = new WsProvider(process.env.WSS_PROVIDER);
    const api = await ApiPromise.create({ provider: wsProvider });

    const keyring = new Keyring({ type: "ed25519" });
    const userKeyring = keyring.addFromMnemonic(process.env.MNEMONIC_PHRASE);
    

    // maximum gas to be consumed for the instantiation. if limit is too small the instantiation will fail.
    const gasLimit = 500000n * 1000000n;
    
    // a limit to how much Balance to be used to pay for the storage created by the instantiation
    // if null is passed, unlimited balance can be used
    const storageDepositLimit = null


    // Sign transaction to deploy contract
    //Define deployed contract with metadata + contract address
    const contract = new ContractPromise(api, metadata, '5GEMqSuQUCgYCoR5zZSzCX1of68o7F2pnyUapmkJhvbwT2BD');
    
    

    // Query value from contract
    const {result, output } = await contract.query.get(
    userKeyring.address,
    {
        gasLimit,
        storageDepositLimit,
    }
    );
    // check if the call was successful
    if (result.isOk) {
        // output the return value
        console.log('Success -> Value:', output.toHuman());
    } else {
        console.error('Error', result.asErr);
    }
 
}



main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

Error:

I can not query get function in incrementer smart contract through @polkadot/api-contract. I try to replicate this context in contracts-ui -> its working properly.

I have no idea why I encounter this issue

Error Type { registry: TypeRegistry {}, initialU8aLength: 6 }

Environment:

  • Dependencies:

package.json

{
  "dependencies": {
    "@polkadot/api": "10.1.3",
    "@polkadot/api-contract": "10.1.3"
  },
  "type": "module"
}
1
  • Anyone used to get issue
    – CocDap
    Commented May 22, 2023 at 2:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.