Send transactions web3 provider WalletConnect

This is fine, i am able to achieve this. This is not the problem. I am doing a BNB transaction and at that time i want to do it via wallet connect. How do i do that? Also i only want to do it on main network so i need to know the chainId!

Also there is a problem with specifying chainId in the walletconnect authenticate . If you try authenticating on testnet , it also goes through , even though i mentioned chainid as 56

You need to create custom web3 variable in case you want use WC:

const user = await Moralis.authenticate({ provider: "walletconnect" });
const web3 = await Moralis.Web3.activeWeb3Provider.activate();

To make transaction:

web3.eth.sendTransaction({to: "address_1", from:"address_2", value: Moralis.Units.ETH

In your frontend you can use all chains you want. It doesn’t work this way. Chains on server settings - chains from which server will sync info.

I will try this one!

No that’s ok. In authenticate for wallet connect if i mention 56, and if i am on testnet of metamask, it is still authenticating me. Which i guess is wrong as chain id is different.

chainId can be specified only for walletconnect

I ve sent you a solution for metamask chain detecting above

We will add this to SDK soon, but it is not so easy and not so quick to do. And it will probably not work this way how it works for walletconnect. Because these two wallets have completely different logic.

Yes thankyou i will try these options.

1 Like

Hi activeweb3provider doesn’t exists after we reload the page? So how do we keep it per session? I can not store it in a session as it gives circular error! What is the use of authenticate if authenticate is no more there after refresh happens? How do i solve it?

Also if i do not refresh , it executes the transaction but it doesn’t take me to the wallet to approve the transaction, i need to go to wallet manually from my browser . It works seemless on pancakeswap , how do i make it like pancakeswap?

Thank you for your patience @Son

The user session is not equal web3 provider session. You need to call web3provider after reloading the page. Could you post the code for reproducing the smart contract call issue? Thank you :raised_hands:

I do this inside my login session

And store web3 globally or in window.web3

Then in my buy method which is called after the refresh has happened -

I call

web3.eth.sendTransaction

Now the problem is web3 is no more available as it is refreshed.

And if i don’t refresh it works
But it doesn’t take me to my trust wallet on click of buy, i need to go there manually!

Web3 activating and user session do not depend on each other. You need to enable the web3 provider not during authorization, but during page loading.

How can you activate web3 without authenticating via wallet connect, web3 itself is not available on load as it is wallet connect then how can we activate it?

You can call every time when the page is loaded this:

if (window.localStorage.walletconnect) {
  await Moralis.enable({
        provider: "walletconnect"
      });
}

After connecting via WC in the localstorage the walletconnect object is written. So you can easily check if it is there

This helped , finally i am able to adjust everything! Thankyou so much.

I am doing the check on page load for wallet connect then enabling it and then on buy i am checking the chain id and activating current provider , then doing transaction. So it works fine for wallet connect and from inside metamask browser.

There are few issues like if i go through metamask via walletconnect - buy doesn’t work.

For trust wallet it works but i need to open trust wallet app manually and approve transaction!

Do you know any way of opening it directly with transaction - just like pancakeswap does?

There are few issues like if i go through metamask via walletconnect - buy doesn’t work.

If I remember correctly there was an issue with non-trustwallet wallets. I’ll let you know when it will be fixed.

For trust wallet it works but i need to open trust wallet app manually and approve transaction!

I’m not sure if I got your question right. Before sending any transactions you need to approve it from your wallet. What is the problem, please describe it in more detail. I only use pancake using metamask.

So the problem is when i click buy, it triggers a transaction for approval but i need to manually open the trustwallet app and then approve it, it is not automatically going to trustwallet as it does it in pancakeswap. This is in mobile chrome/safari browser.

it is not automatically going to trustwallet as it does it in pancakeswap

What it does automatically? Opens the app?

Do you connect on pancakeswap via TWT or wallectconnect+TWT?