We have this error:
Error: Internal JSON-RPC error.
at getJsonRpcError (errors.js:176:12)
at Object.internal (errors.js:42:24)
at provider.sendAsync (openloginJrpc.esm.js:792:73)
at async provider.request (openloginJrpc.esm.js:813:17)
Some part of the code:
const web3authProvider = useWeb3authStore((state) => state.provider);
const sendTransaction = async ({
amount,
recipient,
}: {
amount: number;
recipient: string;
}): Promise<any> => {
if (web3authProvider) {
try {
const rpc = new RPC(web3authProvider);
const transaction = await rpc.sendTransaction({ amount, recipient });
console.log(transaction);
} catch (error) {
console.log(error);
}
}
};
'use client';
import { type ReactElement, useEffect } from 'react';
import { Web3AuthNoModal } from '@web3auth/no-modal';
import type { CustomChainConfig } from '@web3auth/base';
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider';
import { OpenloginAdapter } from '@web3auth/openlogin-adapter';
import { useWeb3authStore } from '@/stores/web3authStore/web3authStore';
const Web3AuthInit = (): ReactElement => {
/* web3auth connection */
useEffect(() => {
const init = async (): Promise<void> => {
try {
const chainConfig = {
chainNamespace: 'eip155',
chainId: '0x13881',
// rpcTarget: 'https://rpc.ankr.com/polygon_mumbai/',
rpcTarget: 'https://polygon-mumbai.infura.io/v3/df5e93d0b48343659ad62d5bf345e546',
displayName: 'Mumbai Testnet',
blockExplorer: 'https://mumbai.polygonscan.com/',
ticker: 'MATIC',
tickerName: 'Matic',
};
const CLIENT_ID = process.env.NEXT_PUBLIC_WEB3AUTH_CLIENTID ?? '';
const web3auth = new Web3AuthNoModal({
clientId: CLIENT_ID,
web3AuthNetwork: 'sapphire_devnet', // Web3Auth Network
chainConfig: chainConfig as Partial<CustomChainConfig> &
Pick<CustomChainConfig, 'chainNamespace'>,
});
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig },
});
const openloginAdapter = new OpenloginAdapter({
loginSettings: {
mfaLevel: 'none',
},
adapterSettings: {
whiteLabel: {
defaultLanguage: 'es',
},
loginConfig: {
jwt: {
verifier: 'WEB3AUTH-CUSTOM-JWT-v01',
typeOfLogin: 'jwt',
clientId: CLIENT_ID,
},
},
},
privateKeyProvider,
});
web3auth.configureAdapter(openloginAdapter);
useWeb3authStore.setState({ web3auth });
await web3auth.init();
useWeb3authStore.setState({ provider: web3auth.provider });
if (web3auth.connected) {
useWeb3authStore.setState({ loggedIn: true });
}
} catch (error) {
console.error(error);
}
};
void init();
}, []);
/* web3auth connection end */
return <> </>;
};
export default Web3AuthInit;
import type { IProvider } from '@web3auth/base';
import Web3 from 'web3';
export default class EthereumRpc {
private readonly provider: IProvider;
constructor(provider: IProvider) {
this.provider = provider;
}
async getChainId(): Promise<string> {
try {
const web3 = new Web3(this.provider as any);
// Get the connected Chain's ID
const chainId = await web3.eth.getChainId();
return chainId.toString();
} catch (error) {
return error as string;
}
}
async getAccounts(): Promise<string[]> {
try {
const web3 = new Web3(this.provider as any);
return await web3.eth.getAccounts();
} catch (error: unknown) {
return error as string[];
}
}
async getBalance(): Promise<string> {
try {
const web3 = new Web3(this.provider as any);
const accounts = await web3.eth.getAccounts();
const balance = await web3.eth.getBalance(accounts[0]);
return web3.utils.fromWei(balance, 'ether');
} catch (error) {
return error as string;
}
}
async sendTransaction(destinationAccount: string): Promise<string> {
try {
const web3 = new Web3(this.provider as any);
const accounts = await web3.eth.getAccounts();
console.log(accounts);
const txRes = await web3.eth.sendTransaction({
from: accounts[0],
to: destinationAccount,
value: web3.utils.toWei('0.001', 'ether'),
maxPriorityFeePerGas: '5000000000', // Max priority fee per gas
maxFeePerGas: '6000000000000', // Max fee per gas
});
return txRes.transactionHash.toString();
} catch (error) {
return error as string;
}
}
async signMessage(): Promise<string | undefined> {
try {
const web3 = new Web3(this.provider as any);
const accounts = await web3.eth.getAccounts();
const message = '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad';
(web3.currentProvider as any)?.send(
{
method: 'eth_sign',
params: [accounts[0], message],
from: accounts[0],
},
(err: Error, result: any) => {
if (err) {
console.error(err);
return;
}
return result;
},
);
} catch (error) {
return error as string;
}
}
}
'use client';
import { type ReactElement, useState } from 'react';
import { useWeb3authStore } from '@/stores/web3authStore/web3authStore';
import RPC from '@/blockchain/evm.web3';
const Page = (): ReactElement => {
const [showData, setShowData] = useState('');
const web3auth = useWeb3authStore((state) => state.web3auth);
const web3authProvider = useWeb3authStore((state) => state.provider);
const sendTransaction = async () => {
if (web3authProvider) {
const rpc = new RPC(web3authProvider);
const tx = await rpc.sendTransaction('0xf61585d10622b799fd05f8a9bab50211b563cea6');
console.log(tx, '----------TX----------');
}
};
-
SDK Version:
β@web3auth/no-modalβ: β^7.2.0β, -
Platform:
NextJS, Flutter -
Browser Console Screenshots:
-
If the issue is related to Custom Authentication, please include the following information (optional):
-
Verifier Name:
WEB3AUTH-CUSTOM-JWT-v01 -
JWKS Endpoint:
https://authz.novacoin.net/certs/jwks.json
-
-
Sample idToken (JWT):
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjIwMjNURVNUdjAxcHhCQHpwdmNZcDhVZW1lcC5KVnYtTGRzNy54Y1Y0In0.eyJzdWIiOiI2NTVlOTMwMzRlMDIzMTExMTVkMzI2MzEiLCJmdWxsX25hbWUiOiJBbmRyZXNzIFZhbGVuY2lhIiwiZW1haWwiOiJiZW5qdW1lYUBnbWFpbC5jb20iLCJhdWQiOiJ1cm46bm92YWNvaW46bmV0IiwiaXNzIjoiaHR0cHM6Ly91c2Vycy5kZXYubm92YWNvaW4iLCJmaWVsZHMiOnsiaWROdW0iOiI4NzY1NDMyMSIsInBhc3N3b3JkIjoiJDJiJDEyJHV6QXBZSklJTUVlZFI4M1FGYzRXTmVVQ0ZLT24zWHhyd3QzQXVlUlZ0U3hvOXJZeDVXSXNtIiwiaWRUeXBlIjoiQ0MiLCJuYXRpb25hbElkIjoiQ08ifSwiaWF0IjoxNzAyOTYwNTEwLCJleHAiOjE3MDI5NjQxMTB9.EeKzXsACEaEl0-e30nQdhUlfVWkgvvNm3CE7EFE7MS2U1tAw4nExE-cAyCko5Arpy4-mWE6XzwgxQ5VAViCzZpnOfC64LAYBM00P4EXZFBuZIWvv50QAWjHtyPsOBElKi42_bK0txnjouGSB-ul-AANOO6TQdzJyLZ5k3y8GoYyJFAjIUje4zj8pKwRgTcSWkW3S8rF7MsswAbDIDfxnlgUoQ9N-uNxsfUh9E3a-pi2JLyqTymmBLWntCe6ZHyAznMWVGkotrwzDGxi8OymFx-ORE1FGjfi9eV75ISt5xDR_MaUHdYO5IOh0Q-Mu8c6XfBcLAKZtFk9Z3CCUymvlcg
Also, kindly provide the Web3Auth initialization and login code snippet below. This will help us better understand your issue and provide you with the necessary assistance.