You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
async function getSignedData(publicAddress, jsonData) {
|
|
const signedData = await window.ethereum.request({
|
|
method: 'eth_signTypedData_v3',
|
|
params: [publicAddress, JSON.stringify(jsonData)]
|
|
});
|
|
console.log(signedData);
|
|
return signedData
|
|
}
|
|
|
|
async function confirmAvalanche(){
|
|
try {
|
|
await ethereum.request({
|
|
method: 'wallet_switchEthereumChain',
|
|
params: [{ chainId: '0xA86A' }],
|
|
});
|
|
} catch (switchError) {
|
|
// This error code indicates that the chain has not been added to MetaMask.
|
|
if (switchError.code === 4902) {
|
|
try {
|
|
await ethereum.request({
|
|
method: 'wallet_addEthereumChain',
|
|
params: [{
|
|
chainId: '0xA86A',
|
|
chainName: 'Avalanche',
|
|
nativeCurrency: {
|
|
name: 'Avalanche',
|
|
symbol: 'AVAX',
|
|
decimals: 18,
|
|
},
|
|
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'],
|
|
blockExplorerUrls: ['https://snowtrace.io'],
|
|
}],
|
|
});
|
|
} catch (addError) {
|
|
// handle "add" error
|
|
}
|
|
}
|
|
// handle other "switch" errors
|
|
}
|
|
}
|