When should "enableWeb3()" be called?

In the last version of the SDK, where ethers is used: when, in what situations, should enableWeb3() be called?

How does the function related to authenticating user or authorising a wallet?

“… enableWeb3()” enabled web3 – for WHAT? WHAT will happen if it’s not enabled? Can it be enabled automatically? Does it have to get enabled always? Does it enable web3.js or ethers.js (in the laters version of SDK) or simply WEB3 functionality?

Does “authenticate()” enable web3 under the hood?

Why is that not discribed anywhere?!!

I have a react app.

Enable web3 is required to let the browser know your app is using web3 functionalities, So all the stuff related to crypto wallet connection/transactions etc… can work only after web3 is enabled.

You can read more about Moralis web3 functionalities here https://github.com/MoralisWeb3/react-moralis#-table-of-contents

From https://github.com/MoralisWeb3/react-moralis#-table-of-contents

Nothing else can be added. Perfect. "function “enabledWeb3()” is INDEED a function to … guess what … enable web3!

Again, what about my other questions? The only reason I’ve asked them is that there’s no information anywhere, not even in that link which I’d seen before I created this topic. Nor have I’ve understood still.

Why enable it? How is it related to “authenticate()”? Do they have to be called together or not?

If together – in a certain order? Which?

Where is all that information?

Before getting into the questions understand that web browsers did not completely adapt communication to blockchains. So we use web.js which is a software library to help users communicate with blockchains using the browsers.
So enabling web3 is like asking the web3 software to run and prepare to communicate with the blockchain.

You only need to authenticate only when you need to add something on the blockchain (eg. transaction) or to get the wallet addresses of your users to do the same. How is it related to web3? It is one of a function of the web3.js software.

You need to enable web3 to use authenticate not vice versa.

Calling it together or not is up to the functionality of your dapp. You want it, you add it.

These are some of the basics on how blockchain, dapp programming works, either you google it or you can take a course on the same.

If I am missing anything please let me know. :blush:

enambleWeb3 connects to metamask plugin in your browser in order to be able send request to the blockchain
when you authenticate, you use metamask and automatically it will also enable web3 so that you can use metamask

1 Like

My questions aren’t about the basis or what web3 is.
My questions were about using SDK of moralis properly when it comes to dealing with enableWeb3(). And some example. In the documentation it’s not explained - why, how, when… it’s only briefly shown.

Everything in Moralis SDK is about web3, in once sense or other. What do you mean “You want it, you add it.”? In which cases may I not want it?

When on Earth does “enableWeb3()” have to be called, how, at what stage? Should I call only once or every time?

That’s helpful.
But where in the documentation is automatically mentioned at all?

That already contradicts what @cryptokid has just said.

Does “enableWeb3()” have to be called first, in order to use “authenticate()”, “logout()” and so on…? Or not?

That may be an implicit assumption. Web3 is used to communicate with a RPC node. Anytime you need to communicate with a node, for example to send transactions, you will use web3. There are also cases when you can use web3api to call a read only function with runContractFunction where you don’t need a web3 connection.

1 Like

Is that literally “anytime” - before ANY call to Moralis RPC node?
Or is it “if I’ll need it at some point, I must call it now, once, when my web app is starting up”?

You can call it once when the page is loaded and it should be enough. If you call it more than once it should know that it was called before and to get it from cache directly.

1 Like

What do you mean “can”? Why “should be”? Is it optinal? Depend on my mind or the phase of the moon?

I’ve asked about “when does it HAVE to be called”?

you have to call it before you use a function that needs it, like for example Moralis.executeFunction, until you use it you don’t necessarily have to call it, but you can call it anytime before that.

1 Like