Skip to main content

Features

Initialization

The init method is a fundamental feature of the Fuse Wallet Flutter SDK that enables you to setup a wallet & authenticate the user's provided credentials. When you send a request to the server using this method, it verifies the credentials and returns a JSON Web Token (JWT) if the credentials are valid. The JWT is then used to make authenticated API requests, which allows you to access the Fuse Wallet API securely.

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

const publicApiKey = 'YOUR_API_KEY';
const credentials = new ethers.Wallet(process.env.PRIVATE_KEY as string);
const fuse = await FuseSDK.init(publicApiKey, credentials);

Access the wallet

// Create Wallet
const smartContractAddress = fuseSDK.wallet.getSender();
console.log(`Smart contract wallet address: ${smartContractAddress}`);

Sponsored transactions are the ability to pay for another user’s transaction fees. To do this, the Fuse operator must enable the sponsored feature in his project and deposit some funds into the paymaster contract. The SDK provides a middleware to check if the project is sponsored and the amount of funds available for sponsoring.

To use this feature, you must first initialize the SDK with the withPaymaster parameter set to true.

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

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

Send transactions

Send single transaction

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

const res = await fuseSDK.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);

Batch Transactions

Execute a batch of transactions atomically.

const to = "RECIPIENT_ADDRESS";
const value = parseEther("0.001");
const data = Uint8Array.from([]);
const res = await fuseSDK.executeBatch([
{ to, value, data },
{ to, value, data },
{ to, value, data },
]);

console.log(`UserOpHash: ${res?.userOpHash}`);
console.log("Waiting for transaction...");

const receipt = await res?.wait();
console.log("Transaction Hash:", receipt?.transactionHash);

Was this page helpful?