7

From the docs:

// The Contract interface
let abi = [ ... ];

// Connect to the network
let provider = ethers.getDefaultProvider();

// The address from the above deployment example
let contractAddress = "...";

// We connect to the Contract using a Provider, so we will only
// have read-only access to the Contract
let contract = new ethers.Contract(contractAddress, abi, provider);

I understand how this works, but I'm curious if you need the ABI at all? In web3.js, you don't, thanks to the ability to pass a contract method as a string:

// in web3.js
contract.methods["someMethod()"]()
4

As of version 4.x, the answer is yes, the contract ABI must be provided. Creating a contract with no ABI and no provider or signer:

let tokenContract = new ethers.Contract(tokenAddress);

Yields this error:

TypeError: Cannot read property 'forEach' of undefined

Creating a contract with just no provider or signer:

let tokenContract = new ethers.Contract(tokenAddress, erc20Abi);

Yields this other error:

Error: invalid signer or provider (arg="signerOrProvider", value=undefined, version=4.0.41)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.