SDK
Safe Factory

Safe Factory reference

create

Returns an instance of the Safe Factory.


_10
import { SafeFactory } from '@safe-global/protocol-kit'
_10
_10
const safeFactory = await SafeFactory.create({ ethAdapter })

  • 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.create({ ethAdapter, isL1SafeSingleton: true })

  • 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.


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

  • 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.create({ ethAdapter, safeVersion })

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: Web3TransactionOptions = {
_10
from, // Optional
_10
gas, // Optional
_10
gasPrice, // Optional
_10
maxFeePerGas, // Optional
_10
maxPriorityFeePerGas // Optional
_10
nonce // Optional
_10
}


_10
const options: EthersTransactionOptions = {
_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?