Quick Start
Create your first FunWallet within 60 seconds.
Get started by following one of the many examples outlined throughout this documentation. All examples on this website are intended to be run in Node.js. For example, to run quick-start.js, type node quick-start.js after installing the necessary packages.
Alternatively, fork our open source demo app.
Below is a step by step guide on how to get started with the FunWallet SDK. The following example transfers 10 USDC from a FunWallet to DEST_ADDR on the Göerli testnet (default network), authorizing the transaction with a private key.
Install FunWallet
yarn add fun-wallet ethers@5.7.2
Import required objects
quick-start.js
const ethers = require("ethers")const { FunWallet, configureEnvironment } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")
View imports in React.js
Set API key (optional)
Fun API keys are used to access our internal bundler systems which submit transactions to the selected blockchain. By default, every FunWallet SDK flow uses the following API key: MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq, which is rate-limited and should not be used in production. Get your developer API key by visiting the Fun dashboard.
Run flows with your developer API key by modifying the EnvironmentManager object. You can learn more in Configure Environment.
quick-start.js
const ethers = require("ethers")const { FunWallet, configureEnvironment } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")// Public testing API Keyconst API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"async function main() {// Configure API Key with Funawait configureEnvironment({apiKey: API_KEY})}
Note that this API Key is throttled and used for testing. Get an API key from our dashboard to access full throughput.
Set wallet owner
Wallet owners are entities authorized to execute transactions for a FunWallet. Check out the different FunWallet owner types here.
The easiest way to start is to use a private key as a owner or transaction authorizer. This method is not recommended for production, due to obvious security concerns.
quick-start.js
const ethers = require("ethers")const { FunWallet, configureEnvironment } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"async function main() {await configureEnvironment({apiKey: API_KEY})// Set wallet owner via ethers libraryconst auth = new Eoa({ privateKey: PRIVATE_KEY })const uniqueId = auth.getUniqueId()}
Create FunWallet
quick-start.js
const ethers = require("ethers")const { FunWallet, configureEnvironment } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"async function main() {await configureEnvironment({apiKey: API_KEY})const auth = new Eoa({ privateKey: PRIVATE_KEY })const uniqueId = auth.getUniqueId()// Create a unique FunWallet based on the provided authconst funWallet = new FunWallet( { uniqueId } )}main()
To test the successful completion of this step, run await funWallet.getAddress(). The returned address should be 0x4D139e45c639cA2EEAF1C581166947844129Dd55.
Recall, to create your own wallet either change the owner, or add an unused index with new FunWallet( { uniqueId, index: NEW_IDX } ). You can find out more about the role of indices in the creation of FunWallets here.
Fund wallet (optional)
If your wallet is not funded, then the next step (transfer) will not work becuase you have no assets in the wallet to transfer. If you imported the wallet in this tutorial then there should be USDC in the account.
Transfer USDC
quick-start.js
const ethers = require("ethers")const { FunWallet, configureEnvironment } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"const DEST_ADDR = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"async function main() {await configureEnvironment({apiKey: API_KEY})const auth = new Eoa({ privateKey: PRIVATE_KEY })const uniqueId = auth.getUniqueId()const funWallet = new FunWallet( { uniqueId } )// NOTE: Wallet must be prefunded if not using a sponsor// await fundWallet(funder_auth, wallet, .005)// Transfer 10 USDC from funWallet to DEST_ADDRconst receipt = await funWallet.transfer(auth, {to: DEST_ADDR,amount: 10,token: "USDC"})}main()