soul-wallet-lib
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

soul-wallet-lib

The interaction library for SoulWallet

Compatible ContractsDocumentation

Table of Contents

Features

  • All-In-One

  • UserOperation can be built with a single function

  • Built-in Bundler module

  • Built-in CallData parsing module

  • Built-in common operations, such as ERC20 ERC721 ERC1155 (e.g. you can create a transfer UserOperation with one function)

  • Auto update preVerificationGas (lower deposit requirements for user)

  • ⚠️ Note: current version will refactor the code in the future and cannot guarantee compatibility

Installing

Using npm:

$ npm install git+https://github.com/proofofsoulprotocol/soulwalletlib.git#v0.1.0-alpha.13

Using yarn:

$ yarn add git+https://github.com/proofofsoulprotocol/soulwalletlib.git#v0.1.0-alpha.13

Using pnpm:

$ pnpm add git+https://github.com/proofofsoulprotocol/soulwalletlib.git#v0.1.0-alpha.13

Once the package is installed, you can import the library using import approach:

import { IApproveToken, ITransaction, SoulWalletLib, UserOperation } from 'soul-wallet-lib';

Example

import { ethers } from "ethers";
import { IUserOpReceipt, SoulWalletLib, UserOperation } from 'soul-wallet-lib';

async function main() {
    const soulWalletLib = new SoulWalletLib();

    const walletAddress = await soulWalletLib.calculateWalletAddress(
        '0x0',  // <address> SoulWalletLogic Contract Address
        '0x0',  // <address> EntryPoint Contract Address
        '0x0',  // <address> Wallet Owner Address
        86400,  // <uint32> upgradeDelay (seconds)
        86400,  // <uint32> guardianDelay (seconds)
        '0x0'  // <address> guardianAddress
    );

    const activateOp = soulWalletLib.activateWalletOp(
        '0x0',  // <address> SoulWalletLogic Contract Address
        '0x0',  // <address> EntryPoint Contract Address
        '0x0',  // <address> Wallet Owner Address
        86400,  // <uint32> upgradeDelay (seconds)
        86400,  // <uint32> guardianDelay (seconds)
        '0x0',  // <address> guardianAddress
        '0x',   // <bytes> paymasterAndData
        10000000000,// 100Gwei
        1000000000,// 10Gwei 
    );

    const userOpHash = activateOp.getUserOpHash(
        '0x0',  // <address> EntryPoint Contract Address
        1,      // <uint32> chainId
    );

    activateOp.signWithSignature(
        '0x0',  // <address> Wallet Owner Address
        '0x'    // <bytes> signature of userOpHash
    );


    const bundler = new soulWalletLib.Bundler(
        '0x0',  // <address> EntryPoint Contract Address
        new ethers.providers.JsonRpcProvider('<RPC Provider>'),
    );

    const validation = await bundler.simulateValidation(activateOp);
    if (validation.status !== 0) {
        throw new Error(`error code:${validation.status}`);
    }

    const bundlerEvent = bundler.sendUserOperation(activateOp);
    bundlerEvent.on('error', (err: any) => {
        console.log(err);
    });
    bundlerEvent.on('send', (userOpHash: string) => {
        console.log('send: ' + userOpHash);
    });
    bundlerEvent.on('receipt', (receipt: IUserOpReceipt) => {
        console.log('receipt: ' + JSON.stringify(receipt));
    });
    bundlerEvent.on('timeout', () => {
        console.log('timeout');
    });
}

main();

License

MPL-2.0

Package Sidebar

Install

npm i soul-wallet-lib

Weekly Downloads

16

Version

0.1.1

License

MPL-2.0

Unpacked Size

1.02 MB

Total Files

255

Last publish

Collaborators

  • haha-mike