Send Transactions
In this guide, you will learn how to create Safe transactions, sign them, collect the signatures from the different owners, and execute them.
For more detailed information, see the Starter Kit Reference.
Prerequisites
Install dependencies
First, you need to install some dependencies.
_10pnpm add @safe-global/sdk-starter-kit
Steps
Imports
Here are all the necessary imports for this guide.
_10import { createSafeClient } from '@safe-global/sdk-starter-kit'
Create a signer
Firstly, you need to get a signer, which will be the owner of a Safe account after it's deployed.
This example uses a private key, but any way to get an EIP-1193 compatible signer can be used.
_10const SIGNER_ADDRESS = // ..._10const SIGNER_PRIVATE_KEY = // ..._10const RPC_URL = 'https://rpc.ankr.com/eth_sepolia'
Initialize the SafeClient
When deploying a new Safe account, you need to pass the configuration of the Safe in the safeOptions
property. The Safe account is configured with your signer as the only owner in this case.
_10const safeClient = await createSafeClient({_10 provider: RPC_URL,_10 signer: SIGNER_PRIVATE_KEY,_10 safeOptions: {_10 owners: [SIGNER_ADDRESS],_10 threshold: 1_10 }_10})
Create a Safe transaction
Create an array of Safe transactions to execute.
_10const transactions = [{_10 to: '0x...',_10 data: '0x',_10 value: '0'_10}]
Send the Safe transaction
If you configured your Safe with threshold
equal to 1
, calling the send
method will execute the Safe transaction. However, if the threshold
is greater than 1
the other owners of the Safe will need to confirm the transaction until the required number of signatures are collected.
_10const txResult = await safeClient.send({ transactions })_10_10const safeTxHash = txResult.transactions?.safeTxHash
Confirm the Safe transaction
If the Safe transaction needs to be confirmed by other Safe owners, call the confirm
method from a new SafeClient
instance initialized with each of the signers that need to confirm it.
_10const newSafeClient = await createSafeClient({_10 provider: RPC_URL,_10 signer,_10 safeAddress: '0x...'_10})
Finally, retrieve all the pending Safe transactions from the Safe Transaction Service and confirm the one you just created with each missing owner.
_10const pendingTransactions = await newSafeClient.getPendingTransactions()_10_10for (const transaction of pendingTransactions.results) {_10 if (transaction.safeTxHash !== safeTxHash) {_10 return_10 }_10_10 const txResult = await safeClient.confirm({ safeTxHash })_10}
Recap and further reading
After following this guide, you are able to deploy new Safe accounts and create, sign, and execute Safe transactions with the Starter Kit.