Transfer Tokens
Send tokens to a wallet address or social media handle.
FunWallets can send ERC-20 tokens and base currencies (ETH, MATIC) to:
In both cases, the core logic is the same, with some small variance on how to calculate DEST_ADDR:
await wallet.transfer(auth, { to: DEST_ADDR, amount: AMOUNT, token: "USDC" })
Transfer tokens to a public address
The following flow demonstrates how to transfer 5 USDC on the Göerli testnet to DEST_ADDR.
transfer.js
const { FunWallet, configureEnvironment } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")// Replace these with your ownconst PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"const DEST_ADDR = "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9"const transfer = async () => {await configureEnvironment({apiKey: API_KEY})const auth = new Eoa({ privateKey: PRIVATE_KEY })// Get FunWallet associated with EOAconst uniqueId = await auth.getUniqueId()const wallet = new FunWallet({ uniqueId })// NOTE: Wallet must be prefunded if not using a sponsor// await fundWallet(funder_auth, wallet, .005)// auth: an auth object (see Auth API)// to: who you want to send the funds to// amount: amount to send// token: what you want to sendconst receipt = await wallet.transfer(auth, { to: TO_ADDR, amount: 5, token: "USDC" })}transfer()
Transfer ETH to a Twitter handle
The following flow demonstrates how to transfer 0.00001 ETH on the Göerli testnet to @elonmusk on Twitter.
Once the ETH is transferred, @elonmusk can access these funds by creating a FunWallet with the right Twitter Auth Type & index = 0. This can be done by using Fun's demo app here).
transfer.js
const { FunWallet, configureEnvironment } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")// Replace these with your ownconst PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"const USER_TWITTER_HANDLE = "elonmusk"const CHAIN_ID = "ethereum-goerli"const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"const transfer = async () => {await configureEnvironment({apiKey: API_KEY})const uniqueTwitterId = "twitter###" + USER_TWITTER_HANDLEconst destAddr = await FunWallet.getAddress(uniqueTwitterId, index = 0, CHAIN_ID, API_KEY)const auth = new Eoa({ privateKey: PRIVATE_KEY })const uniqueId = await auth.getUniqueId()const wallet = new FunWallet({ uniqueId })// NOTE: Wallet must be prefunded if not using a sponsor// await fundWallet(funder_auth, wallet, .005)// auth: an auth object (see Auth API)// to: who you want to send the funds to// amount: amount to send// token: what you want to sendconst receipt = await wallet.transfer(auth, {to: destAddr,amount: 0.00001,token: "eth"})}transfer()
Ensure your privateKey starts with '0x'.
Ensure your account has enough funds to transfer and pay for gas. (ie: USDC, ETH)
If the token used is not available, use the token address.
Important!
See full reference for Transfer.