Epoch Protocol Docs
  • Epoch Protocol - Overview
  • What is Epoch Protocol - An Introduction
  • 📄Litepaper
  • Blog
  • Links
  • Account Abstraction
    • ERC 4337
      • Operations
    • Benefits
    • Use-cases
      • Examples
    • More Readings
  • Use Epoch Protocol Automation dApp
    • How to use Epoch Protocol for Intent Automation
    • Onboarding
    • Connect to Dapp
    • Record a transaction
    • Bonus Add NFT Action
    • Execute Transaction right now
    • Time-Based triggers
    • Token Received Trigger
    • Reporting a bug and common fixes
  • Use Epoch SDK
    • Getting Started
    • Intent Automation Module
      • Epoch Bundler
      • Epoch SDK
      • Triggers
      • Examples
        • How to Initialise the Epoch SDK
        • How to Get User's SC Wallet Address
        • Check If User's SC Wallet is Deployed or Not
        • Deploy User's SC Wallet if not Deployed
        • Schedule Token Payment
        • Schedule ETH Transfer on Event Trigger
    • Contracts
Powered by GitBook
On this page
  • Install SDK
  • Setting up Bundler Instance
  • Setting up Account API
  • Generating Valid Nonce for UserOP
  • Sending Transactions
  • Getting Queued UserOps
  • Deleting Queued UserOp

Was this helpful?

  1. Use Epoch SDK
  2. Intent Automation Module

Epoch SDK

PreviousEpoch BundlerNextTriggers

Last updated 11 months ago

Was this helpful?

To send transactions, manage smart contract wallet addresses and signing you can use Epoch SDK

Install SDK

yarn add @epoch-protocol/sdk
# or 
npm i @epoch-protocol/sdk

Setting up Bundler Instance

Bundler Instance is needed to connect to the bundler and perform bundler specific actions like send userOps, getUserOps, getUserOperationHash etc.

You need to the bundlerUrl, address and the chain id to setup Bundler Instance

import { HttpRpcClient } from '@epoch-protocol/sdk'

const bundlerInstance = new HttpRpcClient(bundlerUrl, ENTRY_POINT, parseInt(network.chainId.toString()));
const network = await provider.getNetwork();

Setting up Account API

The Account API is essential to manage user's Smart Contract Wallet.

There are 2 Implementations of the Account API in Epoch's SDK

Simple Account API

import { SimpleAccountAPI } from "@epoch-protocol/sdk";

const ENTRY_POINT = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
const FACTORY_ADDRESS = "0x4A4fC0bF39D191b5fcA7d4868C9F742B342a39c1";

const walletAPIInstance = new SimpleAccountAPI({
  provider,
  entryPointAddress: ENTRY_POINT,
  owner: signer,
  factoryAddress: FACTORY_ADDRESS,
});

SAFE Account API

For SAFE Account API we need the SAFE Config like below, you can use the SAFE config from the SDK itself or you can pass you own.

export interface SafeConfig {
    safeProxyFactory: string;
    singleton: string;
    fallbackModule: string;
    aaModule: string;
    addModuleLib: string;
    salt: BigNumber;
}

The safeConfig and salt are essential to calculate an address for your SAFE Account. If the salt changes the address will change as well. So make sure you keep a standardised Salt for your application.

import { SafeAccountAPI } from "@epoch-protocol/sdk";
import { safeDefaultConfig } from "@epoch-protocol/sdk/dist/src/SafeDefaultConfig";

const walletAPIInstance = new SafeAccountAPI({
    provider,
    entryPointAddress: ENTRY_POINT,
    owner: signer,
    safeConfig: safeDefaultConfig[network.chainId],
    salt: safeDefaultConfig[network.chainId].salt,
});

Note -

  • Connecting an existing ERC4337 Compatible Address is WIP and we'll soon add support for it. For now if you know the correct safeConfig and salt you can use that address as well.

Generating Valid Nonce for UserOP

Nonce For Normal Transactions

You don't need to do anything for a normal transaction to calculate nonce. The SDK takes care of it or you can manually pass in the nonce if you like.

const userOp = await walletAPI.createSignedUserOp({
        target: someAddress,
        data: "0x",
        value: 100000000n,
        // nonce: BigInt(someNonce),
});

Nonce For Automated Transactions

Nonce management through Epoch SDK is slightly different when compared to the usual approach for automated transactions, this is to make sure there are no nonce clashes in case you have many user ops in the queue.

let userOp = {...};

const key = await bundler.getValidNonceKey(userOp);
const nonce = await walletAPI.getNonce(key);

userOp.nonce = nonce;

Sending Transactions

Sending transactions is straightforward.

const userOpHash = await bundler.sendUserOpToBundler(userOp);

// In case of non advanced userops
const txid = await walletAPI.getUserOpReceipt(userOpHash);

Getting Queued UserOps

To get a list of all the transactions that are with the bundler simply run these

const queuedUserOpsList = await bundler.getUserOperations(userAddress);

Deleting Queued UserOp

To delete a specific userOp in the automation queue you need to send a new userOp with the same nonce as the userOp you want to delete.

const deleteOp = await walletAPI.createSignedUserOp({
        target: userSCWalletAddress,
        data: "0x",
        value: 0n,
        nonce: BigInt(userOpToDelete.nonce).toString(),
});

const deleteUserOpHash = await bundler.deleteAdvancedUserOpFromBundler(deleteOp);

Account API Implementation for Eth-Infinitism

You can get the ENTRY_POINT and FACTORY_ADDRESS from the Github

Account API Implementation for SAFE Wallet and

ERC4337 Module only works for The wallet deployed using our SDK will have that version

ENTRY_POINT
SimpleAccount.sol
here
ERC4337 Module
SAFE Version 1.4.1 and above.