Safe Account Abstraction

The Safe{Core} Account Abstraction (AA) SDK aims to bring Account Abstraction to life by integrating Safe with Gelato Relay. This SDK helps developers to abstract the complexity of setting up a smart contract account.

Account Abstraction Kit The AA kit helps user ot create predeterministic smart contract wallets and execute gasless transactions with the Gelato Relay. The safe will only be deployed when the first transaction is sent.

Protocol Kit The Protocol Kit helps interact with the Safe contracts. It enables the creation of new Safe accounts, updating their configuration, and signing and executing transactions, among other features.

Relay Kit The Relay Kit relays Safe transactions, allowing you to get them sponsored by a third party or paid with any supported ERC-20 token.

Safe AA SDKs

As part of the Gelato Raas AA offerings, we have deployed a custom safe-sdk creating following packages

PackageSDK

Safe Protocol Kit

gelato-raas-protocol-kit

Safe AA Kit

gelato-raas-account-abstraction-kit

Safe Relay Kit

gelato-raas-relay-kit

This project showcase how to send Gasless Transactions through a Safe sponsoring the gas with 1Balance

In following examples examples, it will be called the increment() method on this simple counter contract deployed on unreal https://unreal.blockscout.com/address/0xEEeBe2F778AA186e88dCf2FEb8f8231565769C27

Quick Start

  1. Clone the safe repo

  2. Install project dependencies:

yarn install

in the package.json we have already included gelato-raas-protocol-kit, gelato-raas-account-abstraction-kit and gelato-raas-relay-kit

  "gelato-raas-account-abstraction-kit": "^1.3.7",
  "gelato-raas-protocol-kit": "^1.3.6",
  "gelato-raas-relay-kit": "^1.3.7"
  1. Create a .env file with your private config:

cp .env.example .env

You will need to input your Private Key PK and GELATO_RELAY_API_KEY for sponsored transactions, you can get it at https://app.gelato.network

  1. Call the method:

  • Using 1Balance

     yarn aa1Balance

Using 1Balance

const safeTransactionData: MetaTransactionData = {
  to: targetAddress,
  data: nftContract.interface.encodeFunctionData("increment", []),
  value: "0",
  operation: OperationType.Call,
};

const safeAccountAbstraction = new AccountAbstraction(signer);
const sdkConfig: AccountAbstractionConfig = {
  relayPack,
};
await safeAccountAbstraction.init(sdkConfig);

const txConfig = {
  TO: targetAddress,
  DATA: safeTransactionData.data,
  VALUE: "0",
  // Options:
  GAS_LIMIT: gasLimit,
};

const predictedSafeAddress = await safeAccountAbstraction.getSafeAddress();
console.log({ predictedSafeAddress });

const isSafeDeployed = await safeAccountAbstraction.isSafeDeployed();
console.log({ isSafeDeployed });

const safeTransactions: MetaTransactionData[] = [
  {
    to: txConfig.TO,
    data: txConfig.DATA,
    value: txConfig.VALUE,
    operation: OperationType.Call,
  },
];
const options: MetaTransactionOptions = {
  gasLimit: txConfig.GAS_LIMIT,
  isSponsored: true,
};

const response = await safeAccountAbstraction.relayTransaction(
  safeTransactions,
  options
);
console.log(`https://relay.gelato.digital/tasks/status/${response} `);

Output

$ ts-node src/aa-safe-gasless/aa1Balance.ts
{ predictedSafeAddress: '0x68D60c586763879c6614e2eFA709cCae708203c4' }
{ isSafeDeployed: true }
https://relay.gelato.digital/tasks/status/0xc34f62e1b057b298c144c79b3cc16e4e24bc2b1e91ce5cd7660f9b8c1791be91

UI integration together with Web3Auth

Please visit the deployed react mini site on https://gelato-raas-aa.web.app/?network=unreal with a live implementation of web3Auth and safe on unreal

The code can be found at https://github.com/gelatodigital/gelato-raas-aa-ui