اتصال کیفپول مرورگری EVM
EXZIX Wallet exposes a standard EVM provider for websites and decentralized applications. Use EIP-6963 to discover a specific wallet, EIP-1193 request methods to interact with it, and never assume that the active provider is MetaMask.
What is supported
The provider supports standard EVM connection, account and chain discovery, account/network events, native balance and contract reads, message signatures, EIP-712 typed-data signatures, contract calls, contract deployment and native/ERC-20 transaction flows. Approval requests are shown in the user-selected EXZIX Wallet Popup or Side Panel.
- Provider discovery: EIP-6963 and window.ethereum fallback
- Connection: eth_requestAccounts and wallet_requestPermissions
- Network: eth_chainId, net_version and wallet_switchEthereumChain
- Signing: personal_sign, eth_sign and eth_signTypedData_v4
- Transactions: eth_sendTransaction for calls and contract creation
Discover EXZIX Wallet
Modern applications should listen for EIP-6963 announcements and let the user choose a provider. EXZIX announces rdns=com.exzix.wallet and name=EXZIX Wallet. Use window.ethereum only as a compatibility fallback when no announced provider was selected.
const providers = new Map();
window.addEventListener('eip6963:announceProvider', (event) => {
const { info, provider } = event.detail;
if (info?.rdns && provider) providers.set(info.rdns, { info, provider });
});
window.dispatchEvent(new Event('eip6963:requestProvider'));
// Prefer the user's explicit wallet selection in your own wallet picker.
const exzix = providers.get('com.exzix.wallet')?.provider;
const provider = exzix || window.ethereum;
if (!provider) throw new Error('No EVM wallet detected');Connect a website
Call eth_requestAccounts from a clear user action such as a Connect Wallet button. EXZIX shows a confirmation request; only use the returned account after the request resolves. Do not request accounts automatically during page load.
const accounts = await provider.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
const chainId = await provider.request({ method: 'eth_chainId' });
console.log({ account, chainId });Track account and network changes
Subscribe to accountsChanged and chainChanged. Clear cached application state and re-read balances, permissions and contract data whenever either event changes. Always compare the active chain with the chain required by the current operation.
provider.on('accountsChanged', (accounts) => {
account = accounts[0] || null;
resetSessionState();
});
provider.on('chainChanged', (chainId) => {
refreshForChain(chainId);
});Login with a wallet signature
A wallet connection proves access to an address for the current session; it is not a login credential by itself. For login, request a server-generated one-time nonce, include the domain and expiry in the message, ask the user to sign it, and verify the exact message and signature on your server. Never accept a client-supplied nonce.
const message = `Sign in to Example App\nNonce: ${nonce}`;
const signature = await provider.request({
method: 'personal_sign',
params: [message, account],
});
// Send account, message, nonce and signature to your server.
// The server verifies the nonce, domain, expiry and signature.Use EIP-712 for structured authorization
Use eth_signTypedData_v4 when the user is authorizing structured data such as an account session or typed action. Pin the domain name, version, chainId and verifyingContract on the server and reject signatures with a mismatched domain or expired nonce.
const typedData = JSON.stringify({
domain: { name: 'Example App', version: '1', chainId, verifyingContract },
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
],
Login: [
{ name: 'account', type: 'address' },
{ name: 'nonce', type: 'string' },
],
},
primaryType: 'Login',
message: { account, nonce },
});
const signature = await provider.request({
method: 'eth_signTypedData_v4',
params: [account, typedData],
});Read balances and contracts
Read methods do not require a signature. Use eth_getBalance for native balances and eth_call for view or pure contract functions. Use an ABI encoder/decoder from your application stack; the wallet provider transports the request but does not replace your contract ABI.
const balance = await provider.request({
method: 'eth_getBalance',
params: [account, 'latest'],
});
const result = await provider.request({
method: 'eth_call',
params: [{ to: contractAddress, data: encodedCallData }, 'latest'],
});Send contract calls and deploy contracts
Use eth_sendTransaction for both ordinary contract calls and deployments. For a call, provide from, to and ABI-encoded data. For deployment, omit to and provide the complete creation bytecode, including encoded constructor arguments. EXZIX prepares the network fee and asks the user to review and approve; the returned value is a transaction hash.
// Contract call. Encode data with your ABI library.
const txHash = await provider.request({
method: 'eth_sendTransaction',
params: [{
from: account,
to: contractAddress,
data: encodedFunctionData,
value: '0x0',
}],
});
// Contract deployment: omit `to` and provide creation bytecode in `data`.
const deploymentHash = await provider.request({
method: 'eth_sendTransaction',
params: [{ from: account, data: creationBytecode, value: '0x0' }],
});Switch networks safely
Use a hexadecimal chain ID with wallet_switchEthereumChain. EXZIX only switches to networks already enabled in the wallet. wallet_addEthereumChain is intentionally not handled automatically; ask the user to add or enable custom networks in EXZIX Wallet settings, then retry.
await provider.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x38' }], // BNB Smart Chain
});Handle user approval and errors
Every connection, signature and transaction is user-controlled. Treat code 4001 as a user rejection, 4100 as a missing or unauthorized connection, 4902 as an unavailable wallet network, and -32602 as invalid request parameters. Display a safe retry action and do not silently resubmit a transaction after rejection or an unknown result.
- 4001 — user rejected the request
- 4100 — the website is not authorized for the requested account
- 4902 — the requested network is not enabled in the wallet
- -32602 — invalid method parameters
- -32603 or -32000 — wallet or transaction processing failure
Provider and security rules
Use HTTPS in production, keep private keys and wallet unlock data out of your application, and never ask users to paste a private key into a website. Do not identify a wallet by isMetaMask; use EIP-6963 metadata and an explicit user choice. A signature is not a payment confirmation—verify payments from your server and the authoritative blockchain/payment lifecycle.
Minimal integration checklist
Add a visible Connect Wallet button; discover providers with EIP-6963; support provider selection when multiple wallets are installed; subscribe to account and chain changes; use server-issued nonces for login; encode contract data with the correct ABI; show the target, network and amount before requesting a transaction; and test rejection, wrong-network, locked-wallet and pending-transaction states.
رفتن به محتوا
