Bako Safe SDK
Quick Start

Quick Start

Get started with Bako Safe SDK in minutes.

Prerequisites

Installation

Install the SDK and Fuel dependencies:

npm install bakosafe fuels

Or with other package managers:

# yarn
yarn add bakosafe fuels
 
# pnpm
pnpm add bakosafe fuels

Authentication Options

The SDK supports two main authentication flows:

Option 1: API Token (Recommended for CLI/Scripts)

Best for automation, CI/CD pipelines, and server-side applications.

import { BakoProvider, Vault } from 'bakosafe';
 
const provider = await BakoProvider.create(
  'https://mainnet.fuel.network/v1/graphql',
  {
    apiToken: process.env.BAKO_API_TOKEN
  }
);
 
// Create vault from provider credentials
const vault = Vault.createFromProvider(provider);

Option 2: Interactive Authentication

Best for browser-based applications with user interaction.

import { BakoProvider } from 'bakosafe';
 
// Step 1: Setup - generates a challenge
const { code } = await BakoProvider.setup({
  address: userWalletAddress,
  provider: 'https://mainnet.fuel.network/v1/graphql',
  encoder: 'FUEL' // or 'WEB_AUTHN', 'EVM'
});
 
// Step 2: User signs the challenge with their wallet
const signature = await userWallet.signMessage(code);
 
// Step 3: Authenticate with the signature
const provider = await BakoProvider.authenticate({
  challenge: code,
  signature,
  encoder: 'FUEL',
  address: userWalletAddress,
  serverUrl: 'https://api.bako.global'
});

Creating Your First Transaction

Once authenticated, you can create and send transactions:

import { BakoProvider, Vault } from 'bakosafe';
 
async function main() {
  // 1. Authenticate
  const provider = await BakoProvider.create(
    'https://mainnet.fuel.network/v1/graphql',
    { apiToken: process.env.BAKO_API_TOKEN }
  );
 
  // 2. Get your vault
  const vault = await Vault.fromAddress(
    process.env.VAULT_ADDRESS,
    provider
  );
 
  // 3. Create a transfer transaction
  const { tx, hashTxId } = await vault.transaction({
    name: 'My First Transfer',
    assets: [{
      assetId: '0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07', // ETH
      amount: '100000', // in base units
      to: 'fuel1recipient...'
    }]
  });
 
  console.log('Transaction created:', hashTxId);
  console.log('Waiting for signatures at https://safe.bako.global');
 
  // 4. Send when all signatures are collected
  const result = await vault.send(tx);
  console.log('Transaction sent:', result.id);
}
 
main();

Environment Setup

Create a .env file with your credentials:

# Network
NETWORK_URL=https://mainnet.fuel.network/v1/graphql

# Bako Safe
BAKO_API_TOKEN=your-api-token-here
VAULT_ADDRESS=your-vault-address-here

Next Steps