Banana <> Rainbow (Next)
Set up the repo and install packages
Step 1: Create a brand-new Next app
Create a new Next project using an existing project template available here with the name banana-sdk-demo
and now let's move into it.
Step 2: Installing rainbowkit, wagmi and Banana rainbow plugin package
Smart Contracts
We will have a fundamental smart contract for this demo's purpose. There will be two functionalities:
Make a transaction to the blockchain by making a state variable change its value.
Fetch value of state variable
Here is the smart contract code:
You can deploy it using remix.ethereum.org and save the smart contract address.
For your reference, a sample contract has been deployed on polygon Mumbai here it's address:
Building the frontend
We will have a simple front end with some buttons to interact with the blockchain. Although Banana SDK provides you with a smart contract wallet you don't need to worry about its deployment. We handle everything in the SDK so you can just concentrate on building your Dapp.
In _app.js
let's import the required for rainbow
Next project by default sets up pages/index.js
which would be rendered via the home route /
In this tutorial, We will create pages/_app.js
from where we would drill down the context of Rainbow and wagmi. Inside _app.js
let's import packages from wagmi and Rainbow
Importing packages from Rainbowkit
let's import modules required from wagmi
Importing BananaWallet plugin and few chains which are not by default avalaible in wagmi or Rainbow from banana-rainbowkit-plugin
package
Configure chains and providers
Download SampleAbi.js from here SampleAbi.js and put it in abi/SampleAbi.js
and for css you can download it from here and put it into styles/globals.css
and import it in pages/_app.js
after creating _app.js
.
Creating connectors for rainbow
Creating wagmiClient
Providing context of Rainbowkit and wagmi
Putting all together you can find the final App.js file here
Let's start modifying pages/index.js
which will contain logic for doing multiple things with wallet instance
pages/index.js
which will contain logic for doing multiple things with wallet instanceImporting Hooks from wagmi
Extracting signers and providers from wagmi hooks
Implementing function to getChainid of current chain
Implementing function to getBalance of an address
Implementing function to get network info
Implementing function to sign Message using Banana Wallet
implementing function to sendEth
Implementing function to make call to smart contract method
Putting all together
Full code can be found here
PS: if you face unexpected export token issue you can fix it by creating next config file in the root of your project and mentioning banana-rainbowkit-plugin package inside transpilePackages array like this.
If you have any questions please post them Banana SDK Discord forum.
Last updated