SDK
Safe Factory

Safe Factory reference

init

It receives a provider and a signer as required parameters and returns an instance of the Safe Factory.

The provider property can be an EIP-1193 (opens in a new tab) compatible provider or an RPC URL. The signer property can be the signer address or its private key.


_10
import { SafeFactory } from '@safe-global/protocol-kit'
_10
_10
const safeFactory = await SafeFactory.init({
_10
provider,
_10
signer
_10
})

  • The signer property

    A passkey object can be passed as a signer to initialize an instance of the Safe Factory.


_11
import { SafeFactory, PasskeyArgType } from '@safe-global/protocol-kit'
_11
_11
const passkey: PasskeyArgType = {
_11
rawId,
_11
coordinates,
_11
}
_11
_11
const safeFactory = await SafeFactory.init({
_11
provider,
_11
signer: passkey
_11
})

  • The isL1SafeSingleton flag

    Two versions of the Safe contracts are available: Safe.sol (opens in a new tab) that doesn't trigger events to save gas and SafeL2.sol (opens in a new tab) that does, which is more appropriate for L2 networks.

    By default, Safe.sol will only be used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the SafeL2.sol contract will be used unless you add the isL1SafeSingleton flag to force using the Safe.sol contract.


    _10
    const safeFactory = await SafeFactory.init({
    _10
    provider,
    _10
    signer,
    _10
    isL1SafeSingleton: true
    _10
    })

  • The contractNetworks property

    If the Safe contracts aren't deployed to your current network, the contractNetworks property will be required to point to the addresses of the Safe contracts previously deployed by you.


    _36
    import {
    _36
    ContractNetworksConfig,
    _36
    SafeProvider
    _36
    } from '@safe-global/protocol-kit'
    _36
    _36
    const safeProvider = new SafeProvider({ provider, signer })
    _36
    const chainId = await safeProvider.getChainId()
    _36
    _36
    const contractNetworks: ContractNetworksConfig = {
    _36
    [chainId]: {
    _36
    safeSingletonAddress: '<SINGLETON_ADDRESS>',
    _36
    safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>',
    _36
    multiSendAddress: '<MULTI_SEND_ADDRESS>',
    _36
    multiSendCallOnlyAddress: '<MULTI_SEND_CALL_ONLY_ADDRESS>',
    _36
    fallbackHandlerAddress: '<FALLBACK_HANDLER_ADDRESS>',
    _36
    signMessageLibAddress: '<SIGN_MESSAGE_LIB_ADDRESS>',
    _36
    createCallAddress: '<CREATE_CALL_ADDRESS>',
    _36
    simulateTxAccessorAddress: '<SIMULATE_TX_ACCESSOR_ADDRESS>',
    _36
    safeWebAuthnSignerFactoryAddress:'<SAFE_WEB_AUTHN_SIGNER_FACTORY_ADDRESS>',
    _36
    safeSingletonAbi: '<SINGLETON_ABI>', // Optional. Only needed with web3.js
    _36
    safeProxyFactoryAbi: '<PROXY_FACTORY_ABI>', // Optional. Only needed with web3.js
    _36
    multiSendAbi: '<MULTI_SEND_ABI>', // Optional. Only needed with web3.js
    _36
    multiSendCallOnlyAbi: '<MULTI_SEND_CALL_ONLY_ABI>', // Optional. Only needed with web3.js
    _36
    fallbackHandlerAbi: '<FALLBACK_HANDLER_ABI>', // Optional. Only needed with web3.js
    _36
    signMessageLibAbi: '<SIGN_MESSAGE_LIB_ABI>', // Optional. Only needed with web3.js
    _36
    createCallAbi: '<CREATE_CALL_ABI>', // Optional. Only needed with web3.js
    _36
    simulateTxAccessorAbi: '<SIMULATE_TX_ACCESSOR_ABI>' // Optional. Only needed with web3.js
    _36
    safeWebAuthnSignerFactoryAbi: '<SAFE_WEB_AUTHN_SIGNER_FACTORY_ABI>' // Optional. Only needed with web3.js
    _36
    }
    _36
    }
    _36
    _36
    const safeFactory = await SafeFactory.init({
    _36
    provider,
    _36
    signer,
    _36
    contractNetworks
    _36
    })

  • The safeVersion property

    The SafeFactory constructor also accepts the safeVersion property to specify the Safe contract version that will be deployed. This string can take the values 1.0.0, 1.1.1, 1.2.0, 1.3.0 or 1.4.1. If not specified, the DEFAULT_SAFE_VERSION value will be used.


    _10
    const safeVersion = 'X.Y.Z'
    _10
    const safeFactory = await SafeFactory.init({
    _10
    provider,
    _10
    signer,
    _10
    safeVersion
    _10
    })

deploySafe

Deploys a new Safe and returns an instance of the Protocol Kit connected to the deployed Safe. The address of the singleton, Safe contract version, and the contract (Safe.sol or SafeL2.sol) of the deployed Safe will depend on the initialization of the safeFactory instance.


_12
const safeAccountConfig: SafeAccountConfig = {
_12
owners,
_12
threshold,
_12
to, // Optional
_12
data, // Optional
_12
fallbackHandler, // Optional
_12
paymentToken, // Optional
_12
payment, // Optional
_12
paymentReceiver // Optional
_12
}
_12
_12
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig })

This method can optionally receive the saltNonce parameter.


_14
const safeAccountConfig: SafeAccountConfig = {
_14
owners,
_14
threshold,
_14
to, // Optional
_14
data, // Optional
_14
fallbackHandler, // Optional
_14
paymentToken, // Optional
_14
payment, // Optional
_14
paymentReceiver // Optional
_14
}
_14
_14
const saltNonce = '<YOUR_CUSTOM_VALUE>'
_14
_14
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig, saltNonce })

Optionally, some properties can be passed as execution options:


_10
const options: TransactionOptions = {
_10
from, // Optional
_10
gasLimit, // Optional
_10
gasPrice, // Optional
_10
maxFeePerGas, // Optional
_10
maxPriorityFeePerGas // Optional
_10
nonce // Optional
_10
}


_10
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig, safeDeploymentConfig, options })

It can also take an optional callback, which receives the txHash of the Safe deployment transaction before returning a new instance of the Protocol Kit:


_10
const callback = (txHash: string): void => {
_10
console.log({ txHash })
_10
}
_10
_10
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig, callback })

Was this page helpful?