Error with declaring Abi instance and signAndSend function
See original GitHub issueHi, 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
- I’m referencing below ReadMe. https://github.com/polkadot-js/api/tree/master/packages/api-contract
- I created the wasm and metadata accordingly to the tutorial
- Project directory is like below
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
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
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.
Pleasure if anyone could help me out.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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:
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.