The web3 response is now an instance of the EthersJs library. You need to check their docs on how these implementations work.
For example, here is some info on how to use contacts in EthersJs:
The web3 response is now an instance of the EthersJs library. You need to check their docs on how these implementations work.
For example, here is some info on how to use contacts in EthersJs:
Hey Erno, I just upgraded my boilerplate project to be using âmoralisâ: â1.0.4â, and âreact-moralisâ: â1.0.0â,
Can you confirm that I am understanding this update correctly, when run enableWeb3(), then I destructure const {web3} = useMoralis(). The web3 variable is now an instance of ethers?
Since when i log the web3 object it doesnât have any other properties of the old web3 instance or the new ethers instance, am I thinking about this wrong?
Yes thatâs correct. The details are in the first post or in the docs: https://docs.moralis.io/moralis-server/web3/web3
Hey Thanks for your quick response, whatâs throwing me off here is that when I log the instance of ethers, it doesnât have any of the objects/functions, like utils, any idea whatâd be causing that? see screenshot:
Etherjs is very different compare to web3js so some of those field youâre looking for might exist but in a different instance, what are you trying to do here? and any syntax that we can try to help with?
Well for whatever reason I am unable to destructure the instance of ethers from useMoralis(). I believe everything is up to date per my initial post, so Iâm just not sure why I wouldnât be getting the full instance.
I tried installing ethersjs via yarn and that instance of ethersjs works just fine. I wish I could be more helpful in my response Iâm just really unsure regarding what is happening here
Hi,
In order to use etherjs utils functions, do I have to manually import etherjs directly and use it like this:
ethers.utils.xxxx()?
The following was working with web3 and now I canât see utils functions append to the provider when doing:
const web3 = (await Moralis.enableWeb3())
Thanks!
Having the exact same issue on my end! glad I am not crazy ha
Ah I see what you mean. Seems like this is a difference between web3 and ethers. Web3 returns utils etc. as well in the provider. EthersJs does not do this.
You will get back a Web3Provider, so if you want to use other EthersJs functionalities, then you need to import these from EthersJs
Ah Ok i see now, that makes sense, thanks for clarifying!
@YosephKS : Thank you !!
yes, i was still developing under Web3js but now i want to migrate my scripts to ethersjs. I know I have to update my webpages scripts but iâm stuck on only 1 point. If i use the alias of the new Moralis SDK (>= 1.0.7):
<script src="https://unpkg.com/moralis@latest/dist/moralis.js"></script>
i could not figure out how to change the code in my index main.js (itâs for Clone-Rarible-24H) :
window.web3 = await Moralis.enableWeb3();
window.tokenContract = new web3.eth.Contract(tokenContractAbi, TOKEN_CONTRACT_ADDRESS);
window.marketplaceContract = new web3.eth.Contract(marketplaceContractAbi, MARKETPLACE_CONTRACT_ADDRESS);
i have tried tons of syntax combinations regarding some tricks found on this forum + reading the ethersjsâ pages, as adviced by Erno : https://docs.ethers.io/v5/api/contract/example/
For the old web3js syntax:
new web3.eth.Contract(tokenContractAbi, TOKEN_CONTRACT_ADDRESS);
⌠the new syntax for ethers is:
new ethers.Contract(TOKEN_CONTRACT_ADDRESS, tokenContractAbi, providerOrSigner)
But i always finish with an error in browser console such as:
Uncaught (in promise) TypeError: ethers.Contract is not a constructor
If you could tell me how to translate the 3 first lines above, you will earn a lot of Karma points
Guys I have an issue with enabling web3 after the update, Can you help me to fix this?
Hey @Erno , Iâm using react-moralis
and useWeb3ExecuteFunction
to run smart contract functions. It worked fine on version 0.3.11, but after installing the latest version v1.1.0, somehow the function stays in loading and fetching phase. Nothing changed in my code, I used the snippet from github passing the parameters in fetch function. Iâm aware of migration on ether.js, I do await data.wait()
to get my smart contract data, but itâs null
all the time.
If you have any idea, let me know, please.
Thanks for your time and effort!
Hi, i have the same problem, event works fine some times (i can see my log of the current chain, and switch with five differents test chains), but some times no more emit (everything break, but no error)âŚ
I call enableWeb3 in first, no problem.
After that, i call a initEvents function, that create listeners on Moralis.onChainChanged((chain) => {console.log('new chain : â + chain);});
There is an issue from onChainChanged event ?
Thanks in advance !
I confirm, when i use metamask events, no problem :
//Not work everytime, when it break no more event and no error
this.web3.getOnChainEvent((chain: string | null) => {
console.log('Chain changed');
console.log(chain);
this.getNativeBalance();
});
// Work fine
(window as any).ethereum.on("chainChanged", (chain: any) => {
console.log("chain");
console.log(chain);
});
Iâre right, itâs Metamask. I moved from Brave to Firefox installing Metamask there to test it and it passed well. I get all my data and event, huh.
Thanks for direction in debugging.
Hi I used Moralis provider and met issues belowâŚ
How can I set network as âanyâ in Moralis provider to avoid network changes error?
YosephKS,
I tried again today to upgrade my project to Ethers.js, as we have the new SDK 1.1.0, but one more time my browser console returns error : it says my contracts are undefined.
The doc at https://docs.ethers.io/v5/api/contract/example/ is not solving my issue. If i tried to update the old :
new web3.eth.Contract(tokenContractAbi, TOKEN_CONTRACT_ADDRESS);
by this :
const tokenContract = new ethers.Contract(TOKEN_CONTRACT_ADDRESS, tokenContractAbi);
my console reports that ethers is not a constructor.
I tried to import the ethers CDN :
<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js" type="application/javascript"></script>
but the issue remains.
Any migration instructions for Cloud Code?
Do you have more info? When does this error occur?
What code dit you run, and what version are you using?