SDK
Guides
Safe deployment

Safe Deployment

This guide will teach you how to deploy a new Safe using the Protocol Kit. This process includes initializing the Protocol Kit, setting up your Safe configuration, and executing the deployment.

For more detailed information, see the Protocol Kit Reference.

Prerequisites

Install dependencies

First, you need to install some dependencies.


_10
pnpm add @safe-global/protocol-kit viem

Steps

Imports

Here are all the necessary imports for this guide.


_10
import Safe, {
_10
PredictedSafeProps,
_10
SafeAccountConfig,
_10
SafeDeploymentConfig
_10
} from '@safe-global/protocol-kit'
_10
import { sepolia } from 'viem/chains'

Create a signer

You need a signer to instantiate the Protocol Kit. This example uses a private key to obtain a signer, but EIP-1193 (opens in a new tab) compatible signers are also supported. For detailed information about signers, please refer to the Protocol Kit reference.


_10
const SIGNER_PRIVATE_KEY = // ...

Initialize the Protocol Kit

Initialize an instance of the Protocol Kit for each network where you want to deploy a new Safe smart account by calling the init method. Pass the provider with its corresponding value depending on the network, the signer executing the deployment, and the predictedSafe with the Safe account configuration.


_16
const safeAccountConfig: SafeAccountConfig = {
_16
owners: ['0x...', '0x...', '0x...'],
_16
threshold: 2
_16
// More optional properties
_16
}
_16
_16
const predictedSafe: PredictedSafeProps = {
_16
safeAccountConfig
_16
// More optional properties
_16
}
_16
_16
const protocolKit = await Safe.init({
_16
provider: sepolia.rpcUrls.default.http[0],
_16
signer: SIGNER_PRIVATE_KEY,
_16
predictedSafe
_16
})

Predict the Safe address

You can predict the Safe address using the getAddress method in the Protocol Kit.


_10
const safeAddress = await protocolKit.getAddress()

Create the deployment transaction

Create the deployment transaction to deploy a new Safe smart account by calling the createSafeDeploymentTransaction method.


_10
const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction()

Execute the deployment transaction

Once the deployment transaction object is ready, execute it using the provided signer or your preferred external Ethereum client.


_12
const client = await protocolKit.getSafeProvider().getExternalSigner()
_12
_12
const transactionHash = await client.sendTransaction({
_12
to: deploymentTransaction.to,
_12
value: BigInt(deploymentTransaction.value),
_12
data: deploymentTransaction.data as `0x${string}`,
_12
chain: sepolia
_12
})
_12
_12
const transactionReceipt = await client.waitForTransactionReceipt({
_12
hash: transactionHash
_12
})

Reinitialize the Protocol Kit

Once the deployment transaction is executed, connect the new Safe address to the Protocol Kit instance by calling the connect method.


_10
const newProtocolKit = await protocolKit.connect({
_10
safeAddress
_10
})
_10
_10
const isSafeDeployed = await newProtocolKit.isSafeDeployed() // True
_10
const safeAddress = await newProtocolKit.getAddress()
_10
const safeOwners = await newProtocolKit.getOwners()
_10
const safeThreshold = await newProtocolKit.getThreshold()

Recap and further reading

After following this guide, you are able to deploy new Safe smart accounts with the Protocol Kit.

Was this page helpful?