Ethereum & EVM chains
Provider discovery with EIP-6963
/**
* Represents the assets needed to display a wallet
*/
interface EIP6963ProviderInfo {
uuid: string;
name: string;
icon: string;
rdns: string;
}
// EIP-6963 Provider Detail containing wallet info and provider instance
interface EIP6963ProviderDetail {
info: EIP6963ProviderInfo;
provider: EIP1193Provider;
}
// Announce Event dispatched by a Wallet
interface EIP6963AnnounceProviderEvent extends CustomEvent {
type: "eip6963:announceProvider";
detail: EIP6963ProviderDetail;
}
// Request Event dispatched by a DApp
interface EIP6963RequestProviderEvent extends Event {
type: "eip6963:requestProvider";
}
// Store all announced providers by their UUID identifier
const announcedProviders = new Map<string, EIP6963ProviderDetail>();
function initializeEIP6963() {
const onAnnounce = (event: EIP6963AnnounceProviderEvent) => {
const { info, provider } = event.detail;
const key = info.uuid
// Avoid duplicates
if(announcedProviders.has(key)) return
announcedProviders.set(key, { info, provider });
};
// Listen for wallet announcements
window.addEventListener("eip6963:announceProvider", onAnnounce);
// Request all wallets to announce themselves
window.dispatchEvent(new Event("eip6963:requestProvider"));
// Return cleanup function
return () => {
window.removeEventListener("eip6963:announceProvider", onAnnounce);
};
}
// Start listening for wallet announcements
initializeEIP6963()Detecting Trust Wallet
Connecting to Trust Wallet
Request user accounts (connect)
Check connected accounts
Listening for account changes
Working with networks
Listen for network changes
Get current network
Request network switch
Add a new network
Signing messages
Sign arbitrary messages
Sign typed data (EIP-712)
Managing assets
Add token to wallet
Interacting with smart contracts
Send transactions to contracts
Understanding the data field
data fieldHigh level abstractions
Wagmi (React/Vue) and Wagmi Core (framework-agnostic)
Need help?
Last updated
Was this helpful?