Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 1.11 KB

File metadata and controls

21 lines (15 loc) · 1.11 KB

ethers-hardhat-error-handling-issue

A simple test case for the problem with an UNPREDICTABLE_GAS_LIMIT error masking normal rejections on view functions, e.g. ownerOf(id) when the token doesn't exist.

See discussions at:

Adapted from standalone example at NomicFoundation/hardhat#2248 (comment)

Uses Node.js 14.18.3, yarn 1.22.17. To run example: yarn example.

You'll need to set environment variables first:

export INFURA_KEY=...   # your Infura API key (aka project ID)
export PRIVATE_KEY=    # the private key for any Ethereum address

The PRIVATE_KEY is needed to create an account in hardhat.config.js, but it's not used to run any write transactions. The script just invokes function ownerOf(uint256 id) public view returns (address) on an ERC-721 contract. By default the Contract is instantiated with the Ethers provider, not the signer, so it can't be used to sign any write transactions.