Safe Factory reference
create
Returns an instance of the Safe Factory.
_10import { SafeFactory } from '@safe-global/protocol-kit'_10_10const safeFactory = await SafeFactory.create({ ethAdapter })
-
The
isL1SafeSingleton
flagTwo 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, theSafeL2.sol
contract will be used unless you add theisL1SafeSingleton
flag to force using theSafe.sol
contract._10const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeSingleton: true }) -
The
contractNetworks
propertyIf 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._25import { ContractNetworksConfig } from '@safe-global/protocol-kit'_25_25const chainId = await ethAdapter.getChainId()_25const contractNetworks: ContractNetworksConfig = {_25[chainId]: {_25safeSingletonAddress: '<SINGLETON_ADDRESS>',_25safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>',_25multiSendAddress: '<MULTI_SEND_ADDRESS>',_25multiSendCallOnlyAddress: '<MULTI_SEND_CALL_ONLY_ADDRESS>',_25fallbackHandlerAddress: '<FALLBACK_HANDLER_ADDRESS>',_25signMessageLibAddress: '<SIGN_MESSAGE_LIB_ADDRESS>',_25createCallAddress: '<CREATE_CALL_ADDRESS>',_25simulateTxAccessorAddress: '<SIMULATE_TX_ACCESSOR_ADDRESS>',_25safeSingletonAbi: '<SINGLETON_ABI>', // Optional. Only needed with web3.js_25safeProxyFactoryAbi: '<PROXY_FACTORY_ABI>', // Optional. Only needed with web3.js_25multiSendAbi: '<MULTI_SEND_ABI>', // Optional. Only needed with web3.js_25multiSendCallOnlyAbi: '<MULTI_SEND_CALL_ONLY_ABI>', // Optional. Only needed with web3.js_25fallbackHandlerAbi: '<FALLBACK_HANDLER_ABI>', // Optional. Only needed with web3.js_25signMessageLibAbi: '<SIGN_MESSAGE_LIB_ABI>', // Optional. Only needed with web3.js_25createCallAbi: '<CREATE_CALL_ABI>', // Optional. Only needed with web3.js_25simulateTxAccessorAbi: '<SIMULATE_TX_ACCESSOR_ABI>' // Optional. Only needed with web3.js_25}_25}_25_25const safeFactory = await SafeFactory.create({ ethAdapter, contractNetworks }) -
The
safeVersion
propertyThe
SafeFactory
constructor also accepts thesafeVersion
property to specify the Safe contract version that will be deployed. This string can take the values1.0.0
,1.1.1
,1.2.0
,1.3.0
or1.4.1
. If not specified, theDEFAULT_SAFE_VERSION
value will be used._10const safeVersion = 'X.Y.Z'_10const 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.
_12const 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_12const protocolKit = await safeFactory.deploySafe({ safeAccountConfig })
This method can optionally receive the saltNonce
parameter.
_14const 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_14const saltNonce = '<YOUR_CUSTOM_VALUE>'_14_14const protocolKit = await safeFactory.deploySafe({ safeAccountConfig, saltNonce })
Optionally, some properties can be passed as execution options:
_10const options: Web3TransactionOptions = {_10 from, // Optional_10 gas, // Optional_10 gasPrice, // Optional_10 maxFeePerGas, // Optional_10 maxPriorityFeePerGas // Optional_10 nonce // Optional_10}
_10const options: EthersTransactionOptions = {_10 from, // Optional_10 gasLimit, // Optional_10 gasPrice, // Optional_10 maxFeePerGas, // Optional_10 maxPriorityFeePerGas // Optional_10 nonce // Optional_10}
_10const 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:
_10const callback = (txHash: string): void => {_10 console.log({ txHash })_10}_10_10const protocolKit = await safeFactory.deploySafe({ safeAccountConfig, callback })