question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with declaring Abi instance and signAndSend function

See original GitHub issue

Hi, I am trying to develop erc 20 contract with substrate. Now I am struggling to get “total_supply” inside the contract from the frontend. Pleasure if anyone could help me.

Since I’m new as a developer, afraid if information below is not enough.

I’m using Mac, 10.13.6.

Overview

  • Points
  • Errors
  • Source Codes
  • Output with comment outs

Points

Project
|
+ -- basechain/ target/ release/ substrate
|
+ -- contract/ erc20/
|                |
|                  + -- lib.rs
|                  + -- target/
|                        |
|                         + -- erc20.wasm
|                         + -- metadata.json
|                       
+ -- frontend/src/app/pages/Top/TopPage.tsx
  • I got two errors in TopPage.tsx: Abi declaration and signAndSend function.

Errors

Error in declaring Abi instance

image

Type 'import("/Users/Mitsu/coding/shunp/substrate_template/frontend/node_modules/@polkadot/types/types").Registry' parameter, Type 'import("/Users/Mitsu/coding/shunp/substrate_template/frontend/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/types").parameter cannot be assigned.
  Property 'findMetaError' is missing in type 'import("/Users/Mitsu/coding/shunp/substrate_template/frontend/node_modules/@polkadot/types/types").Registry' but required in type 'import("/Users/Mitsu/coding/shunp/substrate_template/frontend/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/types").Registry'.ts(2345)
types.d.ts(297, 5): 'findMetaError' is declared here.

Error in signAndSend Function

image

Property 'signAndSend' does not exist in type 'Call' ts(2339) 

Source Codes

TopPage.tsx

import * as React from 'react';
import { Typography } from '../../../components';
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Abi } from '@polkadot/api-contract';
import { Keyring } from '@polkadot/api';

const abiJson = require('../../../../../contract/erc20/target/metadata.json');
const contractErc20 = '5EzJZcgviPUSGYo2ueBnZ6eUpKf9DCqwocAiVG7bn18VgjYn';

async function ConnectNodeAndContract() {
	const provider = new WsProvider('ws://127.0.0.1:9944');
	const api = await ApiPromise.create({ provider });
	const keyring = new Keyring({ type: 'sr25519' });
	const alice = keyring.addFromUri('//Alice', { name: 'Alice default' });
	const abi = new Abi(api.registry, abiJson);

	console.log(api);
	console.log(api.registry);
	console.log(keyring);

	const [ chain, nodeName, nodeVersion ] = await Promise.all([
		api.rpc.system.chain(),
		api.rpc.system.name(),
		api.rpc.system.version()
	]);

	console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);

	api.tx.contracts
		.call(contractErc20, 'total_supply', '5000', abi.messages.total_supply())
		.signAndSend(alice, console.log('Success'));
}

try {
	ConnectNodeAndContract();
} catch (error) {
	console.error;
} finally {
	process.exit;
}

const TopPage = () => {
	return <Typography>Top page</Typography>;
};
export {};

Output with comment outs

When I comment out lines with errors(new Abi part and api.tx.contracts part), I get below output.

image

Pleasure if anyone could help me out.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mitsu1124commented, Mar 9, 2020

@Sakutaro Hi, thanks for the advice. Actually I got the same advice from Jaco in other channel. Still glad of your kindness.

2020年3月9日(月) 0:30 Sakutaro notifications@github.com:

@mitsu1124 https://github.com/mitsu1124 It might be good to change total_supply to totalSupply.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/polkadot-js/api/issues/1865?email_source=notifications&email_token=AK3YZ2ZCRX36M2WYQXDI5FTRGO227A5CNFSM4KWAFXDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOEY7UA#issuecomment-596217808, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK3YZ26TRUH5CKTOOXMX6YDRGO227ANCNFSM4KWAFXDA .

0reactions
polkadot-js-botcommented, Jun 4, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Better error message if abi is not provided for contract #698
Maybe accessing contract.functions when abi is None should raise an exception that no contract ABI was provided (same for accessing contract.
Read more >
Custom Errors in Solidity
Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).
Read more >
Deploy contract from NodeJS using web3
contract(abi); var contract = MyContract.new({from: web3.eth.accounts[0], data: bc}); returns the same error: MyContract.new is not a function.
Read more >
What is an ABI? explained - step-by-step beginners guides
The ABI indicates the caller of the function to encode the needed information like function signatures and variable declarations in a format that...
Read more >
Etherjs: TypeError: contract.XXX is not a function
Edit I ended by using only the Abi of the functions I want. Example: let signer = new ethers.Wallet(privateKey, provider) let contractAddress =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found