Private Key Auth
Authorize transactions with a private key.
The private key auth type allows FunWallet transactions to be authorized by an ECDSA private key. This option can be useful for testing & debugging.
Create a FunWallet with a private key owner
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()
Transfer assets from a FunWallet with a private key owner
The following example showcases how to initialize a FunWallet with an EOA private key as an owner & transfer tokens to an external address, authorizing this transaction with the private key.
transfer.js
const { FunWallet } = require("fun-wallet")const { Eoa } = require("fun-wallet/auth")const { fundWallet } = require("fun-wallet/utils")const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"const auth = async () => {// Authenticate with Eoa classconst auth = new Eoa({ privateKey: PRIVATE_KEY })const uniqueId = await auth.getUniqueId()// Perform actions with the FunWalletconst wallet = new FunWallet({ uniqueId })// NOTE: Wallet must be prefunded if not using a sponsor// await fundWallet(funder_auth, wallet, .005)await wallet.transfer({ to: '0x175C5611402815Eba550Dad16abd2ac366a63329', amount: .001, token: "eth" })}auth()
More Features
For more features and possibilities with the Fun Wallet, check out the Fun Wallets API.