On this page
2 min read
Transaction templates for the FUSD stablecoin on Flow
The FUSD
contract defines the Flow USD stablecoin token.
FUSD implements the standard FungibleToken contract interface on Flow.
Network | Contract Address |
---|---|
Testnet | 0xe223d8a629e49c68 |
Mainnet | 0x3c5959b568896393 |
Source: FUSD.cdc
This transaction configures the signer's account with an empty FUSD vault.
It also links the following capabilities:
FungibleToken.Receiver
- This capability allows this account to accept FUSD deposits.FungibleToken.Balance
- This capability allows anybody to inspect the FUSD balance of this account.
1// Mainnet2import FungibleToken from 0xf233dcee88fe0abe3import FUSD from 0x3c5959b56889639345// Testnet6// import FungibleToken from 0x9a0766d93b6608b77// import FUSD from 0xe223d8a629e49c6889transaction {1011prepare(signer: AuthAccount) {1213// It's OK if the account already has a Vault, but we don't want to replace it14if(signer.borrow<&FUSD.Vault>(from: /storage/fusdVault) != nil) {15return16}1718// Create a new FUSD Vault and put it in storage19signer.save(<-FUSD.createEmptyVault(), to: /storage/fusdVault)2021// Create a public capability to the Vault that only exposes22// the deposit function through the Receiver interface23signer.link<&FUSD.Vault{FungibleToken.Receiver}>(24/public/fusdReceiver,25target: /storage/fusdVault26)2728// Create a public capability to the Vault that only exposes29// the balance field through the Balance interface30signer.link<&FUSD.Vault{FungibleToken.Balance}>(31/public/fusdBalance,32target: /storage/fusdVault33)34}35}
Source: setup_fusd_vault.cdc
This transaction withdraws FUSD from the signer's account and deposits it into a recipient account. This transaction will fail if the recipient does not have an FUSD receiver. No funds are transferred or lost if the transaction fails.
amount
: The amount of FUSD transfer (e.g. 10.0)recipient
: The recipient account address.
1// Mainnet2import FungibleToken from 0xf233dcee88fe0abe3import FUSD from 0x3c5959b56889639345// Testnet6// import FungibleToken from 0x9a0766d93b6608b77// import FUSD from 0xe223d8a629e49c6889transaction(amount: UFix64, recipient: Address) {1011// The Vault resource that holds the tokens that are being transfered12let sentVault: @FungibleToken.Vault1314prepare(signer: AuthAccount) {15// Get a reference to the signer's stored vault16let vaultRef = signer.borrow<&FUSD.Vault>(from: /storage/fusdVault)17?? panic("Could not borrow reference to the owner's Vault!")1819// Withdraw tokens from the signer's stored vault20self.sentVault <- vaultRef.withdraw(amount: amount)21}2223execute {24// Get the recipient's public account object25let recipientAccount = getAccount(recipient)2627// Get a reference to the recipient's Receiver28let receiverRef = recipientAccount.getCapability(/public/fusdReceiver)!29.borrow<&{FungibleToken.Receiver}>()30?? panic("Could not borrow receiver reference to the recipient's Vault")3132// Deposit the withdrawn tokens in the recipient's receiver33receiverRef.deposit(from: <-self.sentVault)34}35}
Source: transfer_fusd.cdc
This script returns the FUSD balance of an account.
1// Mainnet2import FungibleToken from 0xf233dcee88fe0abe3import FUSD from 0x3c5959b56889639345// Testnet6// import FungibleToken from 0x9a0766d93b6608b77// import FUSD from 0xe223d8a629e49c6889pub fun main(address: Address): UFix64 {10let account = getAccount(address)1112let vaultRef = account13.getCapability(/public/fusdBalance)14.borrow<&FUSD.Vault{FungibleToken.Balance}>()15?? panic("Could not borrow Balance capability")1617return vaultRef.balance18}
Source: get_fusd_balance.cdc