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.
_10import { SafeFactory } from '@safe-global/protocol-kit'_10_10const safeFactory = await SafeFactory.init({_10 provider,_10 signer_10})
-
The
signer
propertyA passkey object can be passed as a signer to initialize an instance of the Safe Factory.
_11import { SafeFactory, PasskeyArgType } from '@safe-global/protocol-kit'_11_11const passkey: PasskeyArgType = {_11 rawId,_11 coordinates,_11}_11_11const safeFactory = await SafeFactory.init({_11 provider,_11 signer: passkey_11})
-
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.init({_10provider,_10signer,_10isL1SafeSingleton: true_10}) -
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._36import {_36ContractNetworksConfig,_36SafeProvider_36} from '@safe-global/protocol-kit'_36_36const safeProvider = new SafeProvider({ provider, signer })_36const chainId = await safeProvider.getChainId()_36_36const contractNetworks: ContractNetworksConfig = {_36[chainId]: {_36safeSingletonAddress: '<SINGLETON_ADDRESS>',_36safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>',_36multiSendAddress: '<MULTI_SEND_ADDRESS>',_36multiSendCallOnlyAddress: '<MULTI_SEND_CALL_ONLY_ADDRESS>',_36fallbackHandlerAddress: '<FALLBACK_HANDLER_ADDRESS>',_36signMessageLibAddress: '<SIGN_MESSAGE_LIB_ADDRESS>',_36createCallAddress: '<CREATE_CALL_ADDRESS>',_36simulateTxAccessorAddress: '<SIMULATE_TX_ACCESSOR_ADDRESS>',_36safeWebAuthnSignerFactoryAddress:'<SAFE_WEB_AUTHN_SIGNER_FACTORY_ADDRESS>',_36safeSingletonAbi: '<SINGLETON_ABI>', // Optional. Only needed with web3.js_36safeProxyFactoryAbi: '<PROXY_FACTORY_ABI>', // Optional. Only needed with web3.js_36multiSendAbi: '<MULTI_SEND_ABI>', // Optional. Only needed with web3.js_36multiSendCallOnlyAbi: '<MULTI_SEND_CALL_ONLY_ABI>', // Optional. Only needed with web3.js_36fallbackHandlerAbi: '<FALLBACK_HANDLER_ABI>', // Optional. Only needed with web3.js_36signMessageLibAbi: '<SIGN_MESSAGE_LIB_ABI>', // Optional. Only needed with web3.js_36createCallAbi: '<CREATE_CALL_ABI>', // Optional. Only needed with web3.js_36simulateTxAccessorAbi: '<SIMULATE_TX_ACCESSOR_ABI>' // Optional. Only needed with web3.js_36safeWebAuthnSignerFactoryAbi: '<SAFE_WEB_AUTHN_SIGNER_FACTORY_ABI>' // Optional. Only needed with web3.js_36}_36}_36_36const safeFactory = await SafeFactory.init({_36provider,_36signer,_36contractNetworks_36}) -
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.init({_10provider,_10signer,_10safeVersion_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.
_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: TransactionOptions = {_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 })