Skip to main content

Connect a dapp to Core

A complete, dependency-free connection flow: detect Core, connect, show the account, survive account and network changes. Everything here is plain browser JavaScript — if you use Wagmi or RainbowKit, the library guides replace all of it.

1. Detect

let coreProvider = null;

window.addEventListener('eip6963:announceProvider', ({ detail }) => {
if (detail.info.rdns === 'app.core.extension') {
coreProvider = detail.provider;
}
});
window.dispatchEvent(new Event('eip6963:requestProvider'));

Run this at startup. If coreProvider is still null when the user clicks connect, Core isn't installed — link them to join.core.app.

2. Connect on user action

Browsers and wallets both assume connection happens on a click, not on page load:

async function connect() {
try {
const [account] = await coreProvider.request({
method: 'eth_requestAccounts',
});
const chainId = await coreProvider.request({ method: 'eth_chainId' });
render({ account, chainId });
} catch (error) {
if (error.code === 4001) return; // user closed the prompt — not an error
throw error;
}
}

document.querySelector('#connect').addEventListener('click', connect);

The first call opens Core's approval screen. On later visits it resolves silently with the already-approved account.

3. Stay in sync

coreProvider.on('accountsChanged', (accounts) => {
if (accounts.length === 0) {
render({ account: null }); // user disconnected from Core's side
} else {
render({ account: accounts[0] });
}
});

coreProvider.on('chainChanged', () => window.location.reload());

Reloading on chainChanged is the blunt-but-correct default: every cached balance, allowance, and contract object is stale after a network switch.

4. Make a request

const balance = await coreProvider.request({
method: 'eth_getBalance',
params: [account, 'latest'],
});
// hex-encoded wei: parseInt(balance, 16) / 1e18 for display

From here, everything in the reference is available — transactions, typed-data signatures, network management.

Test it

Enable testnet mode in Core's settings, fund an account from the faucet, and run the flow against Fuji before mainnet.