跳到主要内容

资产和链

Pali 支持用于 watch 资产和管理 EVM 链的常见钱包方法。

Watch 资产

await window.ethereum.request({
method: 'wallet_watchAsset',
params: {
type: 'ERC20',
options: {
address: tokenAddress,
symbol: 'TOKEN',
decimals: 18,
image: 'https://example.com/token.png',
},
},
});

资产添加到 Pali 前,用户必须批准。

添加 EVM 链

await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: '0x39',
chainName: 'Syscoin NEVM',
nativeCurrency: { name: 'Syscoin', symbol: 'SYS', decimals: 18 },
rpcUrls: ['https://rpc.syscoin.org'],
blockExplorerUrls: ['https://explorer.syscoin.org'],
},
],
});

切换链

await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x39' }],
});

UX 指南

只有在用户开始需要该链的操作时,才请求链变更。不要在页面加载期间强制切换。