Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@actalink/sdk

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@actalink/sdk

ActaLink Account Abstraction SDK

  • 0.0.18
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by22.22%
Maintainers
2
Weekly downloads
 
Created
Source

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);

FAQs

Package last updated on 24 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc