How to integrate Coinbase Smart Wallet into your frontend
Tutorial
Initialize project using create wagmi
Change default config to support Base network and Smart Wallet
Change the config in file src/wagmi.ts
Add Coinbase Blue Connect Wallet Button (optional)
Coinbase Blue Connect Wallet Button comprises of an additional component called CoinbaseWalletLogo.
The below is the code for the same.
To create CoinbaseButton component use the below code and paste in a file.
For example: src/components/CoinbaseButton.tsx
Using Connect Button in UI
If you want not implemented the CoinbaseButton component you can any button of your choice, just make sure to copy the code related to wagmi hooks.
Prompting Transactions
The mint function below is an example of how you can prompt transactions to the user. We are using wagmi’s useWriteContracts hook which allows batching multiple transactions (since Coinbase Smart Wallet supports batching!)
writeContractAsyncwon’t return a transaction hash instead returns a batch id when can be used to further get the batch status, more on that in the next step.
Fetching batch status and transaction hash
Once you have the batch id from writeContractsAsync or writeContracts you can use useCallsStatus hook from wagmi which can fetch the batch status along with the receipt.
useCallsStatus returns receipts for all calls in the batch, if you are sending a single transaction the first recipt should be the receipt for your transaction.
Usage
- Clone the repo
- Install Dependencies
- Start the App