Help & Support

Safe

The Safe{Core} SDK is designed to simplify the integration of Safe smart accounts into your projects, providing a modular and customizable approach to account abstraction. It offers several integration options to cater to different development needs:

  • Starter Kit: A simplified entry point for deploying new accounts and managing Safe transaction flows, including user operations, multi-signature transactions, and message handling.

  • Protocol Kit: Enables interaction with Safe smart accounts, allowing for the creation of new accounts, configuration updates, and transaction execution.

  • API Kit: Facilitates communication with the Safe Transaction Service API, enabling transaction sharing among signers and retrieval of account information such as configurations and transaction histories.

  • Relay Kit: Supports transaction relaying, allowing users to pay transaction fees from their Safe account using native tokens, ERC-20 tokens, or through sponsored transactions.

Creating a Safe

The guide will walkthrough the process of deploying a 2 of 3 Safe Smart Account to Lens Testnet using the Protocol Kit SDK.

1

Install Dependencies

Install the required dependencies with your package manager of choice:

npm install @safe-global/protocol-kit @lens-network/sdk@canary

2

Import Modules

import Safe, {  PredictedSafeProps,  SafeAccountConfig,} from "@safe-global/protocol-kit";import {chains} from "@lens-network/sdk";

3

Initialize Protocol Kit

const safeAccountConfig = {  owners: [    "0x81EdcF8e0a72c3300087891Bb3E992FAf285b2FC",    "0x482c27532517af746358D8E35AfCb3b2ca90A72B",    "0x28f875a08F320Cb5Fb6317c6C948fCA8663aC7e9",  ], // replace with owner addresses  threshold: 2, // replace with multi-signature threshold};
const predictedSafe = {  safeAccountConfig,};
const protocolKit = await Safe.init({  provider: chains.testnet.rpcUrls.default,  signer: process.env.PRIVATE_KEY, // replace with deployer private key  predictedSafe,});

4

Predict Safe Address

You can predict the Safe addres before deployment with the following method:

const safeAddress = await protocolKit.getAddress();

5

Create Deployment Transaction

Create the deployment transaction to deploy a new Safe smart account:

const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction();

6

Execute Deployment Transaction

const client = await protocolKit.getSafeProvider().getExternalSigner();
const transactionHash = await client.sendTransaction({  to: deploymentTransaction.to,  value: BigInt(deploymentTransaction.value),  data: deploymentTransaction.data,  chain: chains.testnet,});
const transactionReceipt = await client.waitForTransactionReceipt({  hash: transactionHash,});

7

Re-Initialize Protocol Kit

Once the deployment transaction is executed, connect the new Safe address to the Protocol Kit instance by calling the connect method. Once connected, operations can be performed by following the Protocol Kit SDK reference.

const newProtocolKit = await protocolKit.connect({  safeAddress,});
const isSafeDeployed = await newProtocolKit.isSafeDeployed();const safeAddress = await newProtocolKit.getAddress();const safeOwners = await newProtocolKit.getOwners();const safeThreshold = await newProtocolKit.getThreshold();