Skip to main content

FuseBox Web SDK

Welcome to the FuseBox Web SDK documentation! This guide will walk you through the process of integrating the SDK into your applications, covering initialization, authentication, and usage of various methods.

Table of Contents

  1. Installation

  2. Getting Started

  3. Available Methods

  4. Example Usage

  5. Additional Information

  6. License

1. Installation

To get started with FuseBox Web SDK, install it using npm:

npm install @fuseio/fusebox-web-sdk

2. Getting Started

Importing FuseBox Web SDK

import { FuseSDK } from "@fuseio/fusebox-web-sdk";

Initializing a Smart Contract Wallet

const fuse = await FuseSDK.init(publicApiKey, credentials, {
withPaymaster: true,
});

Replace 'YOUR_API_KEY' with your actual API key obtained from the Fuse Console Dashboard. If you don’t want to enable Paymaster set it to false. It is default false

Authentication

const userToken = await fuse.authenticate('USER_PRIVATE_KEY');

The authenticate method returns a JSON Web Token (JWT) that will be used for making calls to other methods in the SDK.

3. Available Methods

authenticate

Authenticate a user using their private key and obtain a user token (JWT) for subsequent operations.

const userToken = await fuse.authenticate('USER_PRIVATE_KEY');

init

Initialize the FuseBox Smart Contract Wallet with your API key.

fuse.init({ apiKey: 'YOUR_API_KEY' });

callContract

Call a method on a smart contract deployed on the Fuse Network.

  const to = <RECEIVER_ADDRESS>;
const value = parseEther("0.001");
const data = Uint8Array.from([]);

const res = await fuse.callContract(to, value, data);

console.log(`UserOpHash: ${res?.userOpHash}`);
console.log('Waiting for transaction...');
const receipt = await res?.wait();
console.log('Transaction Hash:', receipt?.transactionHash);

executeBatch

Execute a batch of transactions atomically.

const batchTransactions = [
{ method: 'transfer', parameters: ['RECIPIENT_ADDRESS', 'AMOUNT'] },
// Add more transactions as needed
];
await fuse.executeBatch(batchTransactions, wallet);

getBalance

Retrieve the balance of a wallet.

const balance = await fuse.getBalance(wallet);

getAllowance

Retrieve the allowance of a wallet.

const allowance = await fuse.getAllowance('TOKEN_ADDRESS', 'SPENDER');

getERC20TokenDetails

Retrieve details about an ERC-20 token.

const tokenDetails = await fuse.getERC20TokenDetails('TOKEN_ADDRESS');

4. Example Usage

Creating a Smart Contract Wallet

// createSmartAccountWallet.mjs

// Import necessary libraries
import { ethers } from 'ethers';
import { FuseSDK } from '@fuseio/fuse-web-sdk';

// Main function to create a Smart Account Wallet
const main = async () => {
// Load your private key from the environment variables
const credentials = new ethers.Wallet(process.env.PRIVATE_KEY as string);

// Retrieve your public API key from the environment variables
const publicApiKey = process.env.PUBLIC_API_KEY as string;

// Initialize the Fuse SDK with your public API key and wallet credentials
const fuseSDK = await FuseSDK.init(publicApiKey, credentials);

// Log the sender address of the Smart Wallet
console.log(`Sender Address is ${fuseSDK.wallet.getSender()}`);
};

// Execute the main function
main();

Executing Batch Transactions - Coming Soon!

const batchTransactions = [
{ method: 'transfer', parameters: ['RECIPIENT_ADDRESS', 'AMOUNT'] },
// Add more transactions as needed
];
await fuse.executeBatch(batchTransactions, wallet);

Executing Batch Transactions

const batchTransactions = [
{ method: 'transfer', parameters: ['RECIPIENT_ADDRESS', 'AMOUNT'] },
// Add more transactions as needed
];
await fuse.executeBatch(batchTransactions, wallet);

5. Additional Information

Authentication Token (JWT)

The authenticate method returns a JSON Web Token (JWT) that must be used as the sender parameter in subsequent method calls.

Tutorials

For detailed information on each method and additional features, refer to the How to Guides.

Support and Issues

For support or to report issues, please visit the Fuse Community Forum.

6. License

This project is licensed under the MIT License - see the LICENSE file for details.

Was this page helpful?

Happy React is loading...