FunWallet

Blockchain's most advanced smart wallet

Overview

FunWallet is the core component of the FunWallet SDK. It represents a smart contract wallet deployed (or yet to be deployed) on a Blockchain. FunWallets are responsible for:

  • Asset Custody
  • User Verification
  • Data Orchestration


Constructor


const wallet = new FunWallet()

Methods


transfer

Transfer tokens or base currencies
const receipt = await wallet.transfer(auth, input, options)

Parameters

auth
Ethers.Wallet object
Required

EOA used to authenticate a FunWallet Transaction

input
object
Required

Object containing information such as token/coin type, amount & receiver address

input properties
token
address || string

When used, the transaction becomes an ERC-20 transfer, while its absence defaults to an native token transfer

amount
int
Required

Amount of tokens denoted in token decimal

wallet.transfer(auth,{to:address, token:"usdc", amount:1})
wallet =transfer=> address 1 * 10^6 usdc tokens
to
address
Required

Address receiving the transfer

options
object

Default environment configuration variables to be overridden

Returns

- If options.sentTxLater is false:

receipt
object

Receipt of a Transaction execution/deployment

- If options.sentTxLater is true:

transaction
Transaction object

Signed Transaction object ready to be executed/deployed


swap

Swaps to & from tokens/coins
const receipt = await wallet.swap(auth, input, options)

Parameters

auth
Ethers.Wallet object
Required

EOA used to authenticate a FunWallet Transaction

input
object
Required

Object containing information such as from token, to token, amount, slippage, receiver address pool fee

input properties
in
address || string
Required

Token being swapped

out
address || string
Required

Token recieved from swap

amount
int
Required

Amount of in token to send to swap

returnAddress
address

Return address of swap

slippage
float

Percent slippage allowed.

slippage=10; => "10%"
options
object

Default environment configuration variables to be overridden

Returns

- If options.sentTxLater is false:

receipt
object

Receipt of a Transaction execution/deployment

- If options.sentTxLater is true:

transaction
Transaction object

Signed Transaction object ready to be executed/deployed


approve

Approve a 3rd party to spend a FunWallet's tokens
const receipt = await wallet.approve(auth, input, options)

Parameters

auth
Ethers.Wallet object
Required

EOA used to authenticate a FunWallet Transaction

input
object
Required

Object containing information such as spender, amount & token

input properties
token
address || string
Required

ERC-20 token to approve

amount
int
Required

Amount of tokens denoted in token decimal

wallet.approve(auth,{to:address, token:"usdc", amount:1})
wallet =approve=> address 1 * 10^6 usdc tokens
to
address
Required

Address receiving the approval

options
object

Default environment configuration variables to be overridden

Returns

- If options.sentTxLater is false:

receipt
object

Receipt of a Transaction execution/deployment

- If options.sentTxLater is true:

transaction
Transaction object

Signed Transaction object ready to be executed/deployed


getAddress

Returns a FunWallet's address
const address = await wallet.getAddress(options)

Parameters

options
object

Default environment configuration variables to be overridden

Returns

address
string

Address of a FunWallet


execute

Executes an Action
const receipt = await wallet.execute(auth, actionFunc, options)

Parameters

auth
Ethers.Wallet object
Required

EOA used to authenticate a FunWallet Transaction

actionFunc
function
Required

Function returning Transaction calldata

options
object

Default environment configuration variables to be overridden

Returns

- If options.sentTxLater is false:

receipt
object

Receipt of a Transaction execution/deployment

- If options.sentTxLater is true:

transaction
Transaction object

Signed Transaction object ready to be executed/deployed


sendTx

Sends a Transaction to a blockchain
const receipt = await wallet.sendTx({ auth, tx }, options)

Parameters

auth
Ethers.Wallet object
Required

EOA used to authenticate a FunWallet Transaction

tx
Transaction object
Required

Transaction to be sent to a blockchain

options
object

Default environment configuration variables to be overridden

Returns

receipt
object

Receipt of a Transaction execution/deployment


sendTxs

Sends multiple Transactions to a blockchain
const receipt = await wallet.sendTxs({ auth, txs }, options)

Parameters

auth
Ethers.Wallet object
Required

EOA used to authenticate FunWallet Transactions

tx
List of Transaction objects
Required

Transactions to be sent to a blockchain

options
object

Default environment configuration variables to be overridden

Returns

receipt
object

Receipts of Transaction executions/deployments


execRawTx

A method that allows FunWallets to execute Transactions with arbitrary calldata

const contract = new ethers.Contract(contractAddress,contractAbi)
const input = await contract.populateTransaction.functionName(functionParameters)
const receipt = await wallet.execRawTx(auth, input, options)

Parameters

auth
Object of type Auth
Required

Authenticator of the Transaction

input
Object
Required

Object representing an unsigned Transaction, with elements from, to & data, all values obtained by creating a regular EVM transaction

input properties
to
address
Required
value
int
data
bytes
Required
options
object

Default environment configuration variables to be overridden

Returns

receipt
object

Receipts of Transaction executions/deployments


getAddress

Static method that gets the address of a FunWallet
const address = await FunWallet.getAddress(authId, index, chain, apiKey)

Parameters

authId
String
Required

String representing a FunWallet authenticator's Id. A public key if an EOA and something like 'twitter###my-twitter-username' for social authenticator

index
Int
Required

Index of the FunWallet created with the same authId

chain
String
Required

Chain on which the FunWallet is located

apiKey
object
Required

A developer's Fun API key

Returns

receipt
object

Receipts of Transaction executions/deployments


getAddressOffline

Static method that gets the address of a FunWallet with a single social owner & without needing Fun to be online
const address = await FunWallet.getAddress(authId, index, rpcUrl, factoryAddress)

Parameters

authId
String
Required

String representing a FunWallet authenticator's Id. Something like 'twitter###my-twitter-username'

index
Int
Required

Index of the FunWallet created with the same authId

rpcUrl
String
Required

URL of the RPC to use

factoryAddress
object
Required

The address of the factory smart contract used to create the FunWallet

Returns

receipt
object

Receipts of Transaction executions/deployments