Modifying the Code
Lets modify the code to implement the Data API.
In this section we will modify the code to implement the Data API.
Modify Backend src/app/api/balance/route.ts
First we will implement the getBlockHeight
function. The goal of this function is to fetch recent blocks from the Data API then to return the highest block in the first position.
Next we will implement the listErc20Balances
function. The goal of this function is to fetch the ERC-20 token balances for a given address at a specific block height.
Modify Frontend src/app/balance-app/page.tsx
First we will implement the fetchERC20Balances
function. The goal of this function is to make a call to our backend to get the user's ERC-20 token balances.
Next we will implement the handleSetAddress
function. The goal of this function is to set the address in the state and fetch the ERC-20 token balances for that address using our fetchERC20Balances
function.