11

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()"]()
eth
  • 85,679
  • 53
  • 285
  • 406
Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143

1 Answers1

9

As of v4 at least, 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)

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143