0.0.22 • Published 4 days ago

@actalink/sdk v0.0.22

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
4 days ago

ActaLink account abstraction SDK

Usage

import { SmartAccount, type SmartAccountConfig } from "@actalink/sdk";
...
...
// define configurations for smart account
const config: SmartAccountConfig = {
  chainId,
  provider,
  owner: wallet,
  bundlerUrl: "<bundler URL>",
  paymasterUrl: "<paymaster URL>"
};

const smartWallet = new SmartAccount(config);

// send transaction
const userOpHash = await smartWallet.sendTransaction({
  to: "<contract address>", // Address of contract which we are interacting to. Here USDC contract address.
  data: "<transaction data>",
  value: 0n,
});

Usage with React or NextJS

Note: if you are using SDK in React or Next.js app and using wagmi connector for connecting with wallets then you should configure your provider and signer in ethers.js format.

// hook.ts
import * as React from "react";
import {
  type PublicClient,
  usePublicClient,
  useWalletClient,
  type WalletClient,
} from "wagmi";
import {
  FallbackProvider,
  JsonRpcProvider,
  BrowserProvider,
  JsonRpcSigner,
} from "ethers"; //use ethersv6
import { type HttpTransport } from "viem";

function publicClientToProvider(publicClient: PublicClient) {
  const { chain, transport } = publicClient;
  const network = {
    chainId: chain.id,
    name: chain.name,
    ensAddress: chain.contracts?.ensRegistry?.address,
  };
  if (transport.type === "fallback") {
    const providers = (transport.transports as ReturnType<HttpTransport>[]).map(
      ({ value }) => new JsonRpcProvider(value?.url, network)
    );
    if (providers.length === 1) return providers[0];
    return new FallbackProvider(providers);
  }
  return new JsonRpcProvider(transport.url, network);
}

/**
 * Hook to use a viem Public Client with ethers.js Provider.
 */
export function useEthersProvider({ chainId }: { chainId?: number } = {}) {
  const publicClient = usePublicClient({ chainId });
  return React.useMemo(
    () => publicClientToProvider(publicClient),
    [publicClient]
  );
}

function walletClientToSigner(walletClient: WalletClient) {
  const { account, chain, transport } = walletClient;
  const network = {
    chainId: chain.id,
    name: chain.name,
    ensAddress: chain.contracts?.ensRegistry?.address,
  };
  const provider = new BrowserProvider(transport, network);
  const signer = new JsonRpcSigner(provider, account.address);
  return signer;
}

/**
 * Hook to use a viem Wallet Client with ethers.js Signer.
 */
export function useEthersSigner({ chainId }: { chainId?: number } = {}) {
  const { data: walletClient } = useWalletClient({ chainId });
  return React.useMemo(
    () => (walletClient ? walletClientToSigner(walletClient) : undefined),
    [walletClient]
  );
}
// App.tsx
import {
  useEthersProvider,
  useEthersSigner,
} from "./hooks.ts"; // import hooks from above file
...
const provider = useEthersProvider();
const signer = useEthersSigner();
const config: SmartAccountConfig = {
  chainId,
  provider,
  owner: signer,
  bundlerUrl: "<bundler URL>",
  paymasterUrl: "<paymaster URL>"
};
const smartAccount = new SmartAccount(config);
0.0.21

4 days ago

0.0.22

4 days ago

0.0.20

5 days ago

0.0.19

11 days ago

0.0.18

18 days ago

0.0.17

1 month ago

0.0.16

1 month ago

0.0.15

1 month ago

0.0.14

2 months ago

0.0.13

2 months ago

0.0.12

3 months ago

0.0.11

3 months ago

0.0.10

4 months ago

0.0.9

4 months ago

0.0.8

4 months ago

0.0.7

4 months ago

0.0.6

4 months ago

0.0.5

4 months ago

0.0.4

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago