How to integrate Coinbase Smart Wallet into your frontend
0 viewsTutorial
Initialize project using create wagmi
Change default config to support Base network and Smart Wallet
Change the config in file src/wagmi.ts
123456789101112131415
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.
123456789101112131415161718192021222324252627
To create CoinbaseButton
component use the below code and paste in a file.
For example: src/components/CoinbaseButton.tsx
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
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.
12345678910111213141516171819202122
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!)
writeContractAsync
won'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.
123456789101112131415161718192021222324252627282930
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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
Usage
- Clone the repo
- Install Dependencies
- Start the App