Skip to main content

Quickstart

This guide walks you through a complete shielded payment flow: depositing funds, sending a private transfer, and withdrawing.

Prerequisites

Make sure you have installed the Bermuda SDK before continuing. See the installation guide for setup instructions.

Set env vars ALICE_PRIVATE_KEY and BOB_PRIVATE_KEY for the example script.

Get testnet USDC on Base Sepolia from the Circle faucet onto Alice's address, Bob can have a zero balance.

Example

import sdk from '@bermuda/sdk'
import { Wallet } from 'ethers'

async function main() {
// --- Setup ---
let bermuda = sdk('base-sepolia')
await bermuda._.initBbSync() // WIP - will be abstracted away

const aliceSigner = new Wallet(process.env.ALICE_PRIVATE_KEY!, bermuda.config.provider)
const bobSigner = new Wallet(process.env.BOB_PRIVATE_KEY!, bermuda.config.provider)

let alice = await bermuda.account({ seed: 'seed-alice' })
let bob = await bermuda.account({ seed: 'seed-bob' })

// --- Deposit 1 USDC into Alice's shielded account ---
let depositPayload = await bermuda.deposit({
signer: aliceSigner,
token: bermuda.config.USDC!,
to: alice.address(),
amount: 1_000_000n,
})

await bermuda.relay(depositPayload).then(bermuda.wait)

let aliceBalance = await bermuda.balance(alice)
let bobBalance = await bermuda.balance(bob)
console.log('[deposit] alice balance', aliceBalance.USDC, 'bob balance', bobBalance.USDC)

// --- Transfer 0.8 USDC from Alice to Bob ---
let transferPayload = await bermuda.transfer({
spender: alice,
token: bermuda.config.USDC!,
to: bob.address(),
amount: 800_000n,
})

await bermuda.relay(transferPayload).then(bermuda.wait)

aliceBalance = await bermuda.balance(alice)
bobBalance = await bermuda.balance(bob)
console.log('[transfer] alice balance', aliceBalance.USDC, 'bob balance', bobBalance.USDC)

// --- Withdraw 0.8 USDC from Bob to his public wallet ---
let withdrawalPayload = await bermuda.withdraw({
spender: bob,
token: bermuda.config.USDC!,
amount: 800_000n,
to: bobSigner.address,
})

await bermuda.relay(withdrawalPayload).then(bermuda.wait)

// --- Verify final balances ---
aliceBalance = await bermuda.balance(alice)
bobBalance = await bermuda.balance(bob)
console.log('[withdrawal] alice balance', aliceBalance.USDC, 'bob balance', bobBalance.USDC)
}

main()

Next Steps

Want to interact with smart contracts privately? See DeFi.