This is for when you try any type of function (read or write) or only for write functions?
The default authentication in Moralis is the MetaMask wallet authentication . So, I modified my code that uses web3Auth Authentication as follows and it will additionally authenticate to metamask wallet. Please confirm it works for you @React
try {
user = await Moralis.authenticate({
provider: "web3Auth",
clientId: "BBkCAL8e7ExOJkGz70dbxmQMmLeZpcBZxymzjGk-SWr8gKAQ9gW33NQyQquQbm-nvQbsNSJdiHW0No_26v0TYl8",
chainId: "0x13881"
});
console.log(user);
console.log(user.get('ethAddress'));
// const chainIdHex = await Moralis.switchNetwork("0x13881");
await Moralis.enableWeb3();
} catch(error) {
console.log(error);
}
In this case, when I call Moralis.enableWeb3()
it authenticates with metamask and then looses whatever wallet I was authenticated with via email or any other provider.
Only for write functions, read functions work fine
There may be a way to send parameters to enableWeb3
I agree, I changed my auth code to:
const user = await authenticate({
provider: "web3Auth",
clientId: process.env.CLIENTID,
chainId: "0x13881",
});
await Moralis.enableWeb3({ provider: "web3Auth", clientId: process.env.CLIENTID, chainId: "0x13881" });
enableWeb3 worked, but now on calling some write function on my contract I get this error:
Error: [object Object]
at provider.sendAsync (INetworkController.ts:117:1)
at async provider.request (INetworkController.ts:141:1)
Do you have enough currency in your generated wallet address to pay for the transaction (for social logins)?
Error: [object Object]
Try console.log on that error object to find out what it is.
Thanks a lot! That was the issue, I added enough currency and all working fine now.
@React @alex
i still faced this error, the console log show:
Error: Internal JSON-RPC error.
at getEthJsonRpcError (errors.ts:188:1)
at Object.internal (errors.ts:52:1)
at provider.sendAsync (INetworkController.ts:125:1)
at async provider.request (INetworkController.ts:149:1)
i followed all these above steps and my account has enough ETH, please help me
Hope youâre connected to the proper network ?
I did it, read function still works as usual so i think network is correct.
Only write function is not work
Which chain are you using in Web3Auth and what does your code look like? Are you using the latest @web3auth/web3auth
or CDN package? Are you using the address that Web3Auth generated for your particular login/credentials?
I used the latest @web3auth/web3auth
package 0.5.1
I used chain Rinkeby: 0x4
await enableWeb3({ provider: 'web3Auth', clientId: AppConfig.web3AuthClientId, chainId: '0x4' });
I used account from useMoralis()
const { account } = useMoralis();
I used Moralis.executeFunction
to call contract, it works with read function but not for write.
Please help me
Can you post your executeFunction code. Also check your transaction hash on https://rinkeby.etherscan.io/:
const transaction = await Moralis.executeFunction(options);
console.log(transaction);
Moralis.executeFunction({
contractAddress: CollectionConfig.contractAddress,
abi: nftContractAbi,
params: { _mintAmount: amount },
msgValue: values.tokenPrice.mul(amount),
functionName: 'mint',
})
It throw exception immediately so canât log transaction and there is no any transaction hash on scan.
I used it with provider metamask and it works well, but the error occurs with provider web3Auth
Try another testnet like Goerli / 0x5
, maybe itâs Rinkeby related. Also double check all your params/options, make sure theyâre correct.
Checked params/options, it still works well if i authenticate by metamask provider.
Most of stuffs are now on Rinkeby and try another testnet to get over this error is not really good.
Most of stuffs are now on Rinkeby and try another testnet to get over this error is not really good.
Itâs to test if Rinkeby is the problem or not with Web3Auth. Try another testnet in Web3Auth with the same wallet and do any kind of transaction e.g. send some native currency to a random address to see if it works. Make sure to transfer some money over so the wallet can pay for gas.
i found the error is âtransaction underpricedâ, is there any idea on it
Is this on Rinkeby?
Try re-authenticating via Web3Auth (clear your browserâs cache and localStorage for your app). Or just wait after trying a transaction. The âtransaction underpricedâ error occurs when youâre trying to replace a transaction and the replacing gas price is too low.