Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PromiseContract get abi message error #1551

Closed
jeremymj opened this issue Nov 7, 2019 · 2 comments · Fixed by #1552
Closed

PromiseContract get abi message error #1551

jeremymj opened this issue Nov 7, 2019 · 2 comments · Fixed by #1552
Labels
Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability.

Comments

@jeremymj
Copy link

jeremymj commented Nov 7, 2019

When I tested the contract rpc call method, the main code is as follows:

import { Abi, PromiseContract as ApiContract } from '@polkadot/api-contract';
import { ContractCallOutcome } from '@polkadot/api-contract/types';
import { ApiPromise } from '@polkadot/api';
import { stringToU8a,hexToU8a,hexToString,u8aToHex } from'@polkadot/util';
import * as get_method_test from "../contract_test.json";

const abi_str = (<any>get_method_test);
const abi = getAbiObj(abi_str);

new ApiPromise().isReady.then((api) => {
 
    const contractApi = new ApiContract(api, abi, "5EUE4FAE9wGyxhKdFkhNsm9T8x55VRACzzpPpMDyWEE6h1is");
    const {fn,def} = contractApi.getMessage("get_original_nonce");
    let data = fn();
    console.log("message data:"+u8aToHex(data)); 
    const contract_method = contractApi.call('rpc',def.name,0,500000);
     contract_method.send("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY").then(
        (outcome:ContractCallOutcome):void =>{
            console.log("isSuccess:"+outcome.isSuccess+",value:"+outcome.output.toString());
        }
    );
});

An error message appears when I run:

(node:26072) UnhandledPromiseRejectionWarning: ReferenceError: name is not defined
    at PromiseContract.getMessage (/home/jeremy/work/demo/typescript/substrate-ts-api-test/node_modules/@polkadot/api-contract/base/util.js:38:100)
    at /home/jeremy/work/demo/typescript/substrate-ts-api-test/src/index.ts:13:11

According to the prompt, I find the corresponding file and modify the field corresponding to the line 31,38: After the name is changed to def.name, the program can run normally.But seeing that your apps is working fine, I don't know if I am calling the wrong way.
I use @polkadot/api-contract,@polkadot/api version is 0.96.0-beta.34,test using ABI

@kwingram25
Copy link
Contributor

kwingram25 commented Nov 7, 2019

Thank you for finding this! See if it is fixed after merging #1552 and if not try passing "getOriginalNonce" as well

@jacogr jacogr added -size-xs Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability. labels Nov 7, 2019
@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jun 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants