Setup
This page explains how to integrate Coinbase Wallet SDK as the default provider for your app using web3.js. You can follow a similar pattern if you are using ethers.js.
Setting up Coinbase Wallet SDK
Instructions are in TypeScript. The usage is the same in JavaScript, except for the occasional TypeScript type annotation such as string[]
or as any
.
Prerequisites
- A Typescript project set up locally, created with
yarn create react-app my-app --template typescript
or similar - web3.js installed using
npm install web3
or similar
Initializing
In your App.tsx file, add the following code to initialize Coinbase Wallet SDK and a Web3 object:
Coinbase Wallet SDK uses an rpcUrl provided by Coinbase Wallet clients regardless of the rpcUrl passed into makeWeb3Provider
for whitelisted networks. Wallet SDK needs an rpcUrl to be provided by the app as a fallback.
Next steps:
Troubleshooting
I run into the following error: <b>Module not found: Error: Can't resolve <'assert'/'url/'/...>
I run into the following error: <b>Module not found: Error: Can't resolve <'assert'/'url/'/...>
Due to the removal of default polyfills in webpack5, you must install the following utilities:
Then, add the following code snippet to your webpack.config.js:
If you are using an application built on create-react-app
locally, you must run npm run eject
to be able to customize your webpack configuration.