The Coinbase Wallet SDK connects your app to Coinbase Wallet so it can interact with the Ethereum blockchain.
# npm
npm install @coinbase/wallet-sdk
# yarn
yarn add @coinbase/wallet-sdk-
Compare the installed version with the latest:
# yarn yarn outdated @coinbase/wallet-sdk # npm npm outdated @coinbase/wallet-sdk
-
Update to latest:
# yarn yarn upgrade @coinbase/wallet-sdk --latest # npm npm update @coinbase/wallet-sdk
-
Initialize the SDK
const sdk = createCoinbaseWalletSDK({ appName: 'SDK Playground', });
-
Make Coinbase Wallet Provider
const provider = sdk.evm.getProvider();
-
Request accounts to initialize a connection to wallet
const addresses = provider.request({ method: 'eth_requestAccounts', });
-
Make more requests
provider.request('personal_sign', [ `0x${Buffer.from('test message', 'utf8').toString('hex')}`, addresses[0], ]);
-
Handle provider events
provider.on('connect', (info) => { setConnect(info); }); provider.on('disconnect', (error) => { setDisconnect({ code: error.code, message: error.message }); }); provider.on('accountsChanged', (accounts) => { setAccountsChanged(accounts); }); provider.on('chainChanged', (chainId) => { setChainChanged(chainId); }); provider.on('message', (message) => { setMessage(message); });
-
The Coinbase Wallet SDK test app can be viewed here https://coinbase.github.io/coinbase-wallet-sdk/.
-
To run it locally follow these steps:
- Fork this repo and clone it
- From the root dir run
yarn install - From the root dir run
yarn dev