Provider API
Core Extension injects an EIP-1193
provider into every page. All interaction goes through a single method,
request, plus a small set of events.
request
const accounts = await provider.request({
method: 'eth_requestAccounts',
});
request takes a method name and optional params, and returns a promise.
The promise rejects with a provider error when
the user declines, the dapp lacks permission, or the method fails.
Which object is provider? Any of the entry points Core exposes:
- the provider announced through EIP-6963 (recommended — see Detect Core),
window.avalanche, Core's own conflict-free handle,window.ethereum, shared with other installed wallets.
Events
The provider is an event emitter. Subscribe with on, unsubscribe with
removeListener:
provider.on('accountsChanged', (accounts) => {
if (accounts.length === 0) {
// The user disconnected the dapp.
}
});
provider.on('chainChanged', (chainId) => {
// chainId is a hex string, e.g. '0xa86a' for Avalanche C-Chain.
window.location.reload();
});
| Event | Payload | Fired when |
|---|---|---|
accountsChanged | string[] | The active account changes, or the user disconnects |
chainChanged | string (hex chain id) | The active network changes |
connect | { chainId } | The provider becomes able to serve requests |
disconnect | ProviderRpcError | The provider can no longer serve requests |
message | { type, data } | Subscription updates, for example eth_subscribe |
Method groups
- Core-specific methods — the
avalanche_*andwallet_*surface that sets Core apart. - Signing methods —
personal_signand theeth_signTypedDatafamily. - Standard EVM methods — node RPC that Core proxies to the active network.
- The interactive playground — try any method against your own wallet.