Super Tokens - Frontend Examples
How to Wrap & Unwrap Existing ERC20 Assets
You can easily wrap and unwrap ERC20 assets as super tokens using the Superfluid dashboard, but you might want to write code to allow your users to do the same in your application. In the below examples, we show you 2 code examples which makes it easy to do this using the Superfluid SDK-Core. We’ve used an address that is unlocked and has lots of fake DAI (fDAI) and Super fake DAI (fDAIx) tokens. Feel free to play around and use this code for testing!
Enter an amount to approve and upgrade in the form field below in whole dollar amounts. Make sure you 'Click to Approve Token Upgrade' first, and wait a few seconds after the console shows that the transaction has been completed before you 'Click to Upgrade Your Tokens.'
In this example, we need to approve the super token wrapper contract to spend our DAI before we can call
NOTE: depending on your device, you may need to scroll down in the browser view below to view & click the button to upgrade tokens.
Call approve first, then upgrade your tokens
Next, we can choose to unwrap our ERC20 tokens by calling
downgradeon the super token contract to burn the corresponding super tokens and receive the ERC20 assets back in return.
Downgrading your super tokens
The syntax of working with these assets is a bit different than working with ERC20 Wrapper tokens. There is no underlying ERC20 contract to approve before upgrading, and, like Native Super Tokens, there's no underlying asset address. When upgrading your native assets as Super Tokens, you'll need to call a special function called
upgradeByETHon the native asset super token contract, and pass in a
msg.valuewhich represents the amount of the native asset you'd like to upgrade.
In this example, we're working with ETHx on the Kovan testnet, but the syntax is nearly identical when using native assets on other networks. For example, using MATICx on Polygon or Mumbai would also require calling
upgradeByETHon the contract and passing in the amount you'd like to upgrade as your
msg.value. The only difference is that you'll need to change the address of ETHx/MATICx in the below example to match the deployed address. You can use the network directory for this.
Upgrading a Native Asset