Safe Factory reference
create
Returns an instance of the Safe Factory.
import { SafeFactory } from '@safe-global/protocol-kit'
const safeFactory = await SafeFactory.create({ ethAdapter })-
The
isL1SafeSingletonflagTwo 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.solwill only be used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, theSafeL2.solcontract will be used unless you add theisL1SafeSingletonflag to force using theSafe.solcontract.const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeSingleton: true }) -
The
contractNetworkspropertyIf the Safe contracts aren't deployed to your current network, the
contractNetworksproperty will be required to point to the addresses of the Safe contracts previously deployed by you.import { ContractNetworksConfig } from '@safe-global/protocol-kit' const chainId = await ethAdapter.getChainId() const contractNetworks: ContractNetworksConfig = { [chainId]: { safeSingletonAddress: '<SINGLETON_ADDRESS>', safeProxyFactoryAddress: '<PROXY_FACTORY_ADDRESS>', multiSendAddress: '<MULTI_SEND_ADDRESS>', multiSendCallOnlyAddress: '<MULTI_SEND_CALL_ONLY_ADDRESS>', fallbackHandlerAddress: '<FALLBACK_HANDLER_ADDRESS>', signMessageLibAddress: '<SIGN_MESSAGE_LIB_ADDRESS>', createCallAddress: '<CREATE_CALL_ADDRESS>', simulateTxAccessorAddress: '<SIMULATE_TX_ACCESSOR_ADDRESS>', safeSingletonAbi: '<SINGLETON_ABI>', // Optional. Only needed with web3.js safeProxyFactoryAbi: '<PROXY_FACTORY_ABI>', // Optional. Only needed with web3.js multiSendAbi: '<MULTI_SEND_ABI>', // Optional. Only needed with web3.js multiSendCallOnlyAbi: '<MULTI_SEND_CALL_ONLY_ABI>', // Optional. Only needed with web3.js fallbackHandlerAbi: '<FALLBACK_HANDLER_ABI>', // Optional. Only needed with web3.js signMessageLibAbi: '<SIGN_MESSAGE_LIB_ABI>', // Optional. Only needed with web3.js createCallAbi: '<CREATE_CALL_ABI>', // Optional. Only needed with web3.js simulateTxAccessorAbi: '<SIMULATE_TX_ACCESSOR_ABI>' // Optional. Only needed with web3.js } } const safeFactory = await SafeFactory.create({ ethAdapter, contractNetworks }) -
The
safeVersionpropertyThe
SafeFactoryconstructor also accepts thesafeVersionproperty 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.0or1.4.1. If not specified, theDEFAULT_SAFE_VERSIONvalue will be used.const safeVersion = 'X.Y.Z' 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.
const safeAccountConfig: SafeAccountConfig = {
owners,
threshold,
to, // Optional
data, // Optional
fallbackHandler, // Optional
paymentToken, // Optional
payment, // Optional
paymentReceiver // Optional
}
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig })This method can optionally receive the saltNonce parameter.
const safeAccountConfig: SafeAccountConfig = {
owners,
threshold,
to, // Optional
data, // Optional
fallbackHandler, // Optional
paymentToken, // Optional
payment, // Optional
paymentReceiver // Optional
}
const saltNonce = '<YOUR_CUSTOM_VALUE>'
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig, saltNonce })Optionally, some properties can be passed as execution options:
const options: Web3TransactionOptions = {
from, // Optional
gas, // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
nonce // Optional
}const options: EthersTransactionOptions = {
from, // Optional
gasLimit, // Optional
gasPrice, // Optional
maxFeePerGas, // Optional
maxPriorityFeePerGas // Optional
nonce // Optional
}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:
const callback = (txHash: string): void => {
console.log({ txHash })
}
const protocolKit = await safeFactory.deploySafe({ safeAccountConfig, callback })