ethers.js: Cannot read property '_hex' of undefined
I’m attempting to use a provider/signer obtained from web3Modal and WalletConnect, and then call a Contract method.
const providerOptions = {
walletconnect: {
package: window.WalletConnectProvider.default,
options: {
infuraId: INFURAID,
}
}
};
web3Modal = new window.Web3Modal.default({
cacheProvider: false,
providerOptions,
disableInjectedProvider: false
});
web3Provider = await web3Modal.connect();
provider = new ethers.providers.Web3Provider(web3Provider).provider;
signer = new ethers.providers.Web3Provider(web3Provider).getSigner();
contract = new ethers.Contract(CONTRACTADDRESS, CONTRACTABI, signer);
The next line throws an error:
tx = await contract.myMethod(PARAM1, ethers.utils.formatBytes32String(STRINGPARAM2));
Uncaught TypeError: Cannot read property '_hex' of undefined
This all works just fine when NOT using web3Modal/WalletConnect as a provider, and instead relying on injected MetaMask. I’m not sure what to do or even how to start debugging this. Any help would be wildly appreciated!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (5 by maintainers)
great advice with the console.log. I will try to do that more as I can see how it is helpful along the way. I managed to get it to work by adding quotations in my .env file when defining the variable. I appreciate your help! NEXT_PUBLIC_METAMASK_KEY = YOURPRIVATEKEY NEXT_PUBLIC_METAMASK_KEY = “YOURPRIVATEKEY”
On Wed, Mar 2, 2022 at 11:01 PM Richard Moore @.***> wrote:
Note: the createToken function reverts if a token was already created for the same address and ticket number. This causes ethers to throw BigNumber conversion error in estimateGas for the InfuraProvider. Will create an issue for this later.
@EvilJordan I was able to create a token successfully using your contract on Rinkeby. Here’s the transaction hash
I also created a sample using ethers.js based on the original WalletConnect vanilla javascript example.
The code to call a contract using ethers.js is here:
https://github.com/yuetloo/web3modal-vanilla-js-example/blob/main/example.js#L176-L206
I used your contract on Rinkeby in the example. So, the Create Token section only shows up if you select to connect to the Rinkeby network.