Skip to main content
The following examples use an open-source library of React hooks built for Ethereum called Wagmi. Please create a new file GreenTokenVaultInterface.json in your project to import the ABI and get started on these code examples πŸ‘‡

Depositing into vault

Let’s start with a simple example where we render a component that attempts to deposit 1 token (assuming 18 decimals) to the vault when clicked on.
Note that in order for this to succeed on you must approve the spending amount first on the ERC-20 token for the vault address as the spender. Use depositETH instead if you are integrating with a native token like ETH or Celo

Reading gToken balance

Great! Now we can also read the gToken balance like any other ERC-20 token contract. Doing this is simple with Wagmi using the useBalance hook.
Let’s merge this with the first snippet so that after we deposit we refetch the user’s gToken balance and see it change!

Putting it together

Woo! Now we have a full end-to-end example of a front-end dapp that deposits an ERC-20 token into the gToken vault and refetches the user’s gToken balance 😀