Building Web3 Wallets (Part 3) - Displaying Curve Transactions
In the last section, we built a component that displays the Liquidity Provider (LP) tokens of a wallet address. With the power of GoldRush’s Get Redeemable token balance endpoint, we even managed to find out what the underlying redeemable tokens are worth. This is what our end product looked like:
While it is good to see what LP tokens you have and what can you redeem them for, it is perhaps even more useful to be able to quickly see your interaction history with the Curve protocol. This may be useful if you’re building a DeFi taxation tool, for instance, or a DeFi portfolio manager.
In this section, we’ll build out a Transactions component that shows you all the transactions that a wallet address has made on the Curve protocol. You’ll end up with something like this:
Ready? Let’s get started!
(Estimated time to follow along: 20mins)
Prerequisites
Basic familiarity with React
Some HTML/CSS knowledge
Fetching data using APIs
Tutorial: Building a Curve Transactions Component
1
Figuring out what data you need
- Action: the action associated with the transaction - e.g. 'Swap’ or ‘Add’
- Date: the date of the transaction - e.g. ‘Oct 14’
- Token 1: the token out of wallet - e.g. ‘USDC’
- Token 2: the token received, e.g. ‘USDT’
- Token 1 value: the value of token out, e.g. ‘-$8000’
- Token 2 value: the value of token received, e.g. ‘+$8000’
- Transaction Fees (ETH): fees for the swap, e.g. ‘0.0031 ETH’
- Fees quote (USD): fees for the swap in USD, e.g. ‘($15.00)’
2
Identifying the right GoldRush API endpoint to use
https://api.covalenthq.com/v1/cq/covalent/app/curve/transactions/?address={walletAddress}&key={apiKey}
walletAddress
and apiKey
variables, and pop the endpoint into the browser. If you don’t have a GoldRush API key, you can get it for free here.event_name
(action), block_signed_at
(date), contract_ticker_symbol
(Token 1 ticker), value_quote
(Token 1 value), fees_paid
(fees), and gas_quote
(fees in USD). However, it only contains the token data for one side of the swap. The data for the other side of the swap is in the next item:3
Clone this starter kit & initialize the project
localhost:3000
in your browser. You should see the following:.env
file. Create it at your project root and add your GoldRush API to the REACT_APP_APIKEY
variable, like so:0xc0152cd4c429b7273db278a0355f0dfc9edbe840
.4
Fetching the LP token data
components/Transactions.js
file. Within it, we have the JSX template for the Transactions section. Our goal now is to fetch the relevant data first.Get transactions by wallet address
endpoint above and console.log
the response.npm start
in your terminal.5
Cleaning the data
tx_hash
.6
Rendering the right data
swap
, add_liquidity
, etc).return (
...
<div className='txnContainer'>
<div className='action'>
<div className='actionText'>Swap</div>
...
<div className='actionText'>{item[0].event_name}</div>
<div className='actionText'>{cleanAction(item[0].event_name)}</div>
return(
...
<div className='sectionContainer'>
{data.map(item => {
return (
<div className='rowTxn' key={item}>
<div className='txnContainer'>
<div className='action'>
<div className='actionText'>{cleanAction(item[0].event_name)}</div>
<div className='date'>{new Date(item[0].block_signed_at).toLocaleString('en-US', { day: 'numeric', month: 'short', year: "2-digit" })}</div>
<div className='date'>{new Date(item[0].block_signed_at).toLocaleString('en-US', {timeStyle: 'short' })}</div>
</div>
<div className='tokenBundle'>
<div><img className='tokenLogoTransactions' src='<https://res.cloudinary.com/dl4murstw/image/upload/v1677729872/greybox_zkioqf.png>' alt='tokenlogo'/></div>
<div className='tokeninfo'>
<p className='txnText'>{-(getTokenOut(item).value/(10**getTokenOut(item).contract_decimals)).toFixed(2)}</p>
<p className='txnText'>{getTokenOut(item).contract_ticker_symbol}</p>
</div>
</div>
<div className='arrow'><img src='<https://res.cloudinary.com/dl4murstw/image/upload/v1668500894/next_e7qvca.png>' alt='arrow' height="32px"/></div>
<div className='tokenBundle'>
<div><img className='tokenLogoTransactions' src='<https://res.cloudinary.com/dl4murstw/image/upload/v1677729872/greybox_zkioqf.png>' alt='tokenlogo'/></div>
<div className='tokeninfo'>
<p className='txnText'>+{(-getTokenIn(item).value/(10**getTokenIn(item).contract_decimals)).toFixed(2)}</p>
<p className='txnText'>{getTokenIn(item).contract_ticker_symbol}</p>
</div>
</div>
<div className='rightTxn'>
<div className='gasEth'>{(Number(item[0].fees_paid)/(10**item[0].gas_token_decimals)).toFixed(4)}
<img
alt=""
src="<https://res.cloudinary.com/dl4murstw/image/upload/v1668511869/gas-station_ydpfe5.png>"
height="12"
/>
</div>
<div className='gasQuote'>ETH</div>
<div className='gasQuote'>(${item[0].gas_quote.toFixed(2)})</div>
</div>
</div>
</div>
)
})}
</div>
</>
)
Congratulations. You have managed to build a very compact component that shows you important data on your Curve transactions. All with 1 API call!
In our case, you will realize that what is missing is the token logos. At the point of writing (28th March 2023), the response for Get transactions by wallet address
does not contain a token logo (it might be added in the future). The current workaround is to make use of the Trust wallet repository to render the logos. Apart from that, our component is done.
If you have not been following along and would just like the end state, you can do the following to see this app locally:
git clone https://github.com/xiaogit00/building-wallets.git
cd building-wallets
npm i
git checkout part3-defi-protocols-txns-end
npm start
Just be sure to add your API key in a .env
file, like so:
REACT_APP_APIKEY='ckey_8bdxxxxxxxxxxxxxxxxxxxxxxxxxx99'
All in a Day’s Work
Congratulations on reaching this part of the Building Wallets series. We’ve managed to accomplish quite a bit. In the previous part, we managed to get all the LP token holdings of your users. In this part, we have managed to get all their transactions on Curve.
In the final section, we’ll look at how you can get important data on all Curve’s liquidity pools to display to your users. Stay tuned.