question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property '_hex' of undefined

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DanontheMoon69commented, Mar 3, 2022

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:

I’m not sure what ThirdwebSDK is; the error could be coming from that, perhaps?

Also, can you console.log the environment variable, to make sure the env file is being picked up. It’s a good idea to dump everything to the console to double check things are working.

— Reply to this email directly, view it on GitHub https://github.com/ethers-io/ethers.js/issues/1237#issuecomment-1057668425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXRCQSPNUBWA4XWKGEWHTRDU6BBSRANCNFSM4WAEFZFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: <ethers-io/ethers .@.***>

1reaction
yuetloocommented, Jan 13, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'hex' of undefined (only with v2.3.0) #248
Hi,. I use chalk to add colors to console logs in a personal project (create-cozy-app) and thanks a lot for your great job...
Read more >
react-color Cannot read property 'value' of undefined
It's a very specific error which tells you exactly what the problem is. e.target is undefined , so whatever e is, it has...
Read more >
Cannot read properties of undefined (reading 'toHexString')
Hey Devs I want to interact with this smart contract function but i get this error Cannot read properties of undefined (reading ...
Read more >
A brand new website interface for an even better experience!
Cannot read property 'hex' of undefined.
Read more >
VUEJS - Cannot read properties of null (reading 'hex')"
It's probably not rendering at runtime, so there's a problem accessing the hex element. After loading, he will have access.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found