Wrapped Native Tokens
Introduction
This guide will show you how to deposit and withdraw wrapped native tokens on Flare.
Wrapped tokens are required to delegate your vote power to FTSO data providers and to vote on decisions that affect how Flare networks operate.
Wrapped tokens are stored on the blockchain in an ERC-20
token standard in a smart contract called WNat
.
The IWNat
contract is the interface for the Wrapped Native Token contract.
In this guide, we will use the deposit
and withdraw
functions to wrap and unwrap native tokens:
Deposit
The deposit
function wraps the amount of native tokens you specify in the field.
You can deposit native tokens on the Flare network using the deposit
function in the following code:
import { ethers } from "hardhat";
import { IWNatInstance } from "typechain-types/@flarenetwork/flare-periphery-contracts/coston/IWNat";
const WNAT_ADDRESS = "0x767b25A658E8FC8ab6eBbd52043495dB61b4ea91";
const iWNatArtifact = artifacts.require("IWNat");
// Run with command
// npx hardhat run scripts/wnat/deposit.ts --network coston
async function main() {
const IWNatInstance: IWNatInstance = await iWNatArtifact.at(WNAT_ADDRESS);
// Deposit 0.1 ETH
const depositAmount = ethers.parseEther("0.1").toString();
const tx = await IWNatInstance.deposit({ value: depositAmount });
console.log("Deposited native token to WNAT", tx);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
The most crucial function in the code above is the deposit
function from the IWNat
contract.
With this function, you can deposit native tokens on Flare network and mint wrapped native tokens (WNAT) in return.
Withdraw
Once you have wrapped native tokens, you can withdraw them using the withdraw
function.
It unwraps the amount of native tokens you specify in the input field.
You can withdraw native tokens on the Flare network using the withdraw
function using the following code:
import { ethers } from "hardhat";
import { IWNatInstance } from "typechain-types/@flarenetwork/flare-periphery-contracts/coston/IWNat";
const WNAT_ADDRESS = "0x767b25A658E8FC8ab6eBbd52043495dB61b4ea91";
const iWNatArtifact = artifacts.require("IWNat");
// Run with command
// npx hardhat run scripts/wnat/deposit.ts --network coston
async function main() {
const IWNatInstance: IWNatInstance = await iWNatArtifact.at(WNAT_ADDRESS);
// Deposit 0.1 ETH
const depositAmount = ethers.parseEther("0.1").toString();
const tx = await IWNatInstance.deposit({ value: depositAmount });
console.log("Deposited native token to WNAT", tx);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
You can deposit and withdraw wrapped native tokens to a specific address. Learn more in the IWNat documentation.