Single Factor Auth

Authorize transactions with an EOA.


Single factor auth is the simplest way to authorize FunWallet transactions. With single factor auth, there is only 1 owner of a FunWallet, an EOA, which can be either a Private Key or a Browser Wallet such as Metamask, Rainbow or Coinbase Wallet.


Authorize transactions with a private key

The following example showcases how to create a FunWallet with an EOA private key as an owner & transaction authorizer.

,
SingleAuth.js
const { FunWallet, configureEnvironment } = require("fun-wallet")
const { Eoa } = require("fun-wallet/auth")
const { fundWallet } = require("fun-wallet/utils")
const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"
const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"
const create = async () => {
await configureEnvironment({
apiKey: 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)
const receipt = await wallet.create(auth)
}
create()

Authorize transactions with a browser wallet

The following example showcases how to transfer funds from a FunWallet with a browser wallet as an owner & transaction authorizer using the window.ethereum object.

,
SingleAuth.js
import { ethers } from "ethers"
import { FunWallet, configureEnvironment } from "fun-wallet"
import { Eoa } from "fun-wallet/auth"
import { fundWallet } from "fun-wallet/utils"
const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"
// Call function from frontend
const browserAuth = async () => {
await configureEnvironment({
apiKey: API_KEY
})
// Get provider from browser and create Eoa function
const provider = new ethers.providers.Web3Provider(window.ethereum, "any")
await provider.send('eth_requestAccounts', [])
const eoa = provider.getSigner()
const auth = new Eoa({ signer: eoa })
// Get FunWallet associated with browser Eoa
const uniqueId = await auth.getUniqueId()
const wallet = new FunWallet({ uniqueId })
await fundWallet(auth, wallet, 0.4)
await wallet.transfer(auth, { to: "0x175C5611402815Eba550Dad16abd2ac366a63329", amount: 0.001, token: "eth" })
}
browserAuth()

    Ensure your browser wallet has enough eth to fund the wallet and pay for gas!

    This code is designed to run in React, not Node.