Setting Up Rainbowkit
For the sample project we’ve used Rainbowkit to simplify wallet connections. Rainbowkit gives our frontend project out-of-the-box wallet management for our dapp. It also handles the connection and disconnection of wallets, and supports numerous wallets, swaps connection chains, displays balances and more! If you’re a serious builder, we suggest you read more about creating dApps with Rainbowkit. Unfortunately, the MANTRA Dukong Testnet is not yet supported by Rainbowkit. But, don’t lose heart; we can easily provide the configuration that it needs to work with the Dukong testnet. The sample project is already configured and ready to go.Chains
All we need to do to get Rainbowkit to work with our dApp, is provide the chain configuration. For our sample dApp, you’ll find that configuration in the/frontend/src/chains/mantra.ts file. We configure Dukong like this:
dukong chain into the wagmi.ts configuration file, and add it to the chains array:
Contract Addresses
Our frontend project should now be ready to interact with our deployed contracts. There’s just one more step to complete the configuration, adding our contract addresses. We can do that with local environment variables. First, create a file in the frontend root directory named.env.local. There are two entries that we need:
0x0 is the address of your deployed Whitelist and RealEstateFactory contracts. With environment variables named in this way, they will be made available to our dApp when running locally. There are various methods of providing these values in production environments. It is beyond the scope of this guide to delve into that as it may vary between hosting services.
To get access to these environment variables in our dApp, we get their values and export some constants that we can use when we need to interact with our contracts. We’ve added a file named addresses.ts with the following content to our project’s lib directory:
Interacting With Contracts
Now, let’s take a look at how we interact with our deployed contracts. It is beyond the scope of this guide to go into this in detail. For a detailed explanation with examples, we recommend reading the Rainbowkit and wagmi documentation. Our dApp uses functions provided bywagmi to interact with the Dukong testnet, our connected wallet, and our contracts. The sample app provides several hooks, found in the /frontend/hooks directory. These hooks are used to both read and write transactions on our deployed contracts.
For example, here is the hook for the Whitelist:
useAccount, useReadContract, useWriteContract, and useWaitForTransactionReceipt functions that allow us to get the connected account, send read and write transactions, and wait for our transaction receipts. We can then use this hook (and the others) in our dApps components to provide a meaningful user interface for our users to interact with out contracts.
As an example, below is the ContractInfo component that we use in our dApp to display information about the Whitelist contract:
useWhitelist hook which we use to get the owner address, and a check isOwner to indicate if the connected account is the owner of the Whitelist contract.
We will leave you to read through the other hooks and components to see how we read from our contracts and send transactions. But, as quick example, here is the useDeployProject hook which is used to send a transaction executing the deployProject() function of our RealEstateFactory contract:
NewProjectForm component to provide the user interface for deploying RealEstateToken contracts.
The Completed dApp
With the configuration in place, and our dApp’s components, and hooks etc in place, we can run the dApp locally with the development server. In a terminal you can start the development server with:https://localhost:3000. You should see something like this:
Whitelist administration
The dApp provides a whitelist administration interface where you can approve and revoke investor addresses.Create RealEstateToken projects
You can create new RealEstateToken projects through the dApp interface.Manage RealEstateToken projects
The dApp allows you to manage your RealEstateToken projects, view project details, and mint tokens for approved investors. Of course, yours won’t be immediately populated with data. You will have no whitelisted investor addresses, and no projects. The account that you used to deploy the contracts with Foundry will be the owner of theWhitelist and RealEstateFactory contracts. If you have that account selected in your MetaMask wallet (its address should be shown on the connection button badge in the top right), then you will be able to approve and revoke account addresses as investors.
Any of your accounts should be able to create a new RealEstateToken project. Just provide the required details and hit Create Project. From there, you can head over to the Manage Projects page and mint tokens for your approved investors. The Manage Projects page will display details of the project and the investors and their holdings.