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
  • Simple Account API
  • SAFE Account API

Was this helpful?

  1. Use Epoch SDK
  2. Intent Automation Module
  3. Examples

How to Initialise the Epoch SDK

Simple Account API

import { useEffect, useState } from "react";
import { HttpRpcClient, SimpleAccountAPI } from "@epoch-protocol/sdk";
import { useEthersProvider, useEthersSigner } from "~~/utils/scaffold-eth/common";

export const useBundler = () => {
  const ENTRY_POINT = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
  const FACTORY_ADDRESS = "0x4A4fC0bF39D191b5fcA7d4868C9F742B342a39c1";
  const bundlerUrl: string = process.env.BUNDLER_URL ?? "http://localhost:14337/80001";

  const [walletAPI, setWalletAPI] = useState<SimpleAccountAPI | null>(null);
  const [bundler, setBundler] = useState<HttpRpcClient | null>(null);

  const provider = useEthersProvider(); // Ethers Provider
  const signer = useEthersSigner(); // Ethers Signer

  useEffect(() => {
    (async () => {
      if (signer && provider) {
        const network = await provider.getNetwork();
x
        const walletAPIInstance = new SimpleAccountAPI({
          provider,
          entryPointAddress: ENTRY_POINT,
          owner: signer,
          factoryAddress: FACTORY_ADDRESS,
        });
        setWalletAPI(walletAPIInstance);

        const bundlerInstance = new HttpRpcClient(bundlerUrl, ENTRY_POINT, parseInt(network.chainId.toString()));
        setBundler(bundlerInstance);
      }
    })();
  }, [signer, provider, bundlerUrl]);

  return { walletAPI, bundler };
};

SAFE Account API

import { useEffect, useState } from "react";
import { HttpRpcClient, SafeAccountAPI } from "@epoch-protocol/sdk";
import { safeDefaultConfig } from "@epoch-protocol/sdk/dist/src/SafeDefaultConfig";
import { useEthersProvider, useEthersSigner } from "~~/utils/scaffold-eth/common";

export const useBundler = () => {
  const ENTRY_POINT = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
  const bundlerUrl: string = process.env.BUNDLER_URL ?? "http://localhost:14337/80001";

  const [walletAPI, setWalletAPI] = useState<SafeAccountAPI | null>(null);
  const [bundler, setBundler] = useState<HttpRpcClient | null>(null);

  const provider = useEthersProvider();
  const signer = useEthersSigner();

  useEffect(() => {
    (async () => {
      if (signer && provider) {
        const network = await provider.getNetwork();

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

        const bundlerInstance = new HttpRpcClient(bundlerUrl, ENTRY_POINT, parseInt(network.chainId.toString()));
        setBundler(bundlerInstance);
      }
    })();
  }, [signer, provider, bundlerUrl]);

  return { walletAPI, bundler };
};

Note - The Address in the above examples are for Polygon Mumbai

PreviousExamplesNextHow to Get User's SC Wallet Address

Last updated 11 months ago

Was this helpful?