Safe reference

Initialization

connect

Returns a new instance of the Protocol Kit connected to a new Safe or a new Signer. The new connected signer can be passed via the ethAdapter property while the new connected Safe can be passed using a safeAddress or a predictedSafe.

Connection of a deployed Safe using the safeAddress property:


_10
let protocolKit = await Safe.create({ ethAdapter, safeAddress })
_10
protocolKit = await protocolKit.connect({ ethAdapter: anotherEthAdapter, safeAddress: anotherSafeAddress })

Connection of an undeployed Safe using the predictedSafe property. Because Safes are deployed in a deterministic way, passing a predictedSafe will allow to connect a Safe to the SDK with the Safe configuration:


_10
import { PredictedSafeProps } from '@safe-global/protocol-kit'
_10
_10
const predictedSafe: PredictedSafeProps = {
_10
safeAccountConfig,
_10
safeDeploymentConfig
_10
}
_10
_10
let protocolKit = await Safe.create({ ethAdapter, safeAddress })
_10
...
_10
protocolKit = await protocolKit.connect({ predictedSafe })

  • 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
    protocolKit = await protocolKit.connect({ ethAdapter, safeAddress, 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.


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

create

Returns an instance of the Protocol Kit connected to a Safe. The provided Safe must be a safeAddress or a predictedSafe.

Initialization of a deployed Safe using the safeAddress property:


_10
import Safe from '@safe-global/protocol-kit'
_10
_10
const protocolKit = await Safe.create({ ethAdapter, safeAddress })

Initialization of an undeployed Safe using the predictedSafe property. Because Safes are deployed in a deterministic way, passing a predictedSafe will allow to initialize the SDK with the Safe configuration and use it to some extent before it's deployed:


_10
import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit'
_10
_10
const predictedSafe: PredictedSafeProps = {
_10
safeAccountConfig,
_10
safeDeploymentConfig
_10
}
_10
_10
const protocolKit = await Safe.create({ ethAdapter, predictedSafe })

  • 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 protocolKit = await Safe.create({ ethAdapter, safeAddress, 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 protocolKit = await Safe.create({ ethAdapter, safeAddress, contractNetworks })

Safe Info

getAddress

Returns the address of the current SafeProxy contract.


_10
const safeAddress = await protocolKit.getAddress()

getBalance

Returns the ETH balance of the Safe.


_10
const balance = await protocolKit.getBalance()

getChainId

Returns the chain ID of the connected network.


_10
const chainId = await protocolKit.getChainId()

getContractVersion

Returns the Safe singleton contract version.


_10
const contractVersion = await protocolKit.getContractVersion()

getNonce

Returns the Safe nonce.


_10
const nonce = await protocolKit.getNonce()

Transactions

copyTransaction

Copies a Safe transaction.


_10
const safeTransaction1 = await protocolKit.createTransaction({ transactions })
_10
const safeTransaction2 = await copyTransaction(safeTransaction1)

createRejectionTransaction

Returns a Safe transaction ready to be signed by the owners that invalidates the pending Safe transaction(s) with a specific nonce.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const rejectionTransaction = await protocolKit.createRejectionTransaction(safeTransaction.data.nonce)

createTransaction

Returns a Safe transaction ready to be signed by the owners and executed. The Protocol Kit supports the creation of single Safe transactions but also MultiSend transactions.

This method takes an array of MetaTransactionData objects representing the individual transactions we want to include in our MultiSend transaction.

When the array contains only one transaction, it's not wrapped in the MultiSend.


_16
const transactions: MetaTransactionData[] = [
_16
{
_16
to,
_16
data,
_16
value,
_16
operation // Optional
_16
},
_16
{
_16
to,
_16
data,
_16
value,
_16
operation // Optional
_16
}
_16
// ...
_16
]
_16
const safeTransaction = await protocolKit.createTransaction({ transactions })

This method can also receive the options parameter to set the optional properties in the MultiSend transaction:


_24
const transactions: MetaTransactionData[] = [
_24
{
_24
to,
_24
data,
_24
value,
_24
operation // Optional
_24
},
_24
{
_24
to,
_24
data,
_24
value,
_24
operation // Optional
_24
}
_24
// ...
_24
]
_24
const options: SafeTransactionOptionalProps = {
_24
safeTxGas, // Optional
_24
baseGas, // Optional
_24
gasPrice, // Optional
_24
gasToken, // Optional
_24
refundReceiver, // Optional
_24
nonce // Optional
_24
}
_24
const safeTransaction = await protocolKit.createTransaction({ transactions, options })

In addition, the optional onlyCalls parameter, which is false by default, allows forcing the use of the MultiSendCallOnly instead of the MultiSend contract when sending a batch transaction:


_10
const onlyCalls = true
_10
const safeTransaction = await protocolKit.createTransaction({
_10
transactions,
_10
options,
_10
onlyCalls
_10
})

If the optional properties aren't manually set, the Safe transaction returned will have the default value for each one:

  • operation: OperationType.Call (0) is the default value.
  • safeTxGas: The right gas estimation is the default value.
  • baseGas: 0 is the default value.
  • gasPrice: 0 is the default value.
  • gasToken: 0x address is the default value.
  • refundReceiver: 0x address is the default value.
  • nonce: The current Safe nonce is the default value.

executeTransaction

Executes a Safe transaction.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

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 txResponse = await protocolKit.executeTransaction(safeTransaction, options)

getTransactionHash

Returns the transaction hash of a Safe transaction.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const txHash = await protocolKit.getTransactionHash(safeTransaction)

isValidTransaction

Checks if a Safe transaction can be executed successfully with no errors.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const isValidTx = await protocolKit.isValidTransaction(safeTransaction)

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 isValidTx = await protocolKit.isValidTransaction(safeTransaction, options)

Transaction signatures

approveTransactionHash

Approves a hash on-chain using the current owner account.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const txHash = await protocolKit.getTransactionHash(safeTransaction)
_10
const txResponse = await protocolKit.approveTransactionHash(txHash)
_10
await txResponse.transactionResponse?.wait()

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 txResponse = await protocolKit.approveTransactionHash(txHash, options)

signHash

Signs a hash using the current owner account.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const txHash = await protocolKit.getTransactionHash(safeTransaction)
_10
const signature = await protocolKit.signHash(txHash)

signTransaction

Returns a new SafeTransaction object that includes the signature of the current owner.

You can use multiple signing methods, such as:

  • ETH_SIGN (eth_sign): Regular hash signature
  • ETH_SIGN_TYPED_DATA_V4 (eth_signTypedData_v4): Typed data signature v4, The default method if no signing method is passed
  • ETH_SIGN_TYPED_DATA_V3 eth_signTypedData_v3: Typed data signature v3
  • ETH_SIGN_TYPED_DATA eth_signTypedData: Typed data signature
  • SAFE_SIGNATURE: Signing with another Safe contract as signer

The third parameter (optional) is the preImageSafeAddress. If the preimage is required, this is the address of the Safe that will be used to calculate the preimage. It's a mandatory parameter for 1.3.0 and 1.4.1 contract versions. This is because the safe uses the old EIP-1271 interface, which uses bytes instead of bytes32 for the message; we need to use the pre-image of the message to calculate the message hash. This parameter is used in conjunction with the SAFE_SIGNATURE signing method.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction)

Optionally, an additional parameter can be passed to specify a different way of signing:


_10
const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction, SigningMethod.ETH_SIGN_TYPED_DATA_V4) // Default option
_10
const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction, SigningMethod.ETH_SIGN)
_10
const signedSafeTransaction = await protocolKit.signTransaction(safeTransaction, SigningMethod.SAFE_SIGNATURE, parentSafeAddress).

signTypedData

Signs a transaction according to the EIP-712 using the current signer account.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const signature = await protocolKit.signTypedData(safeTransaction)

Owners

createAddOwnerTx

Returns the Safe transaction to add an owner and optionally change the threshold.


_10
const params: AddOwnerTxParams = {
_10
ownerAddress,
_10
threshold // Optional. If `threshold` isn't provided the current threshold won't change.
_10
}
_10
const safeTransaction = await protocolKit.createAddOwnerTx(params)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createAddOwnerTx(params, options)

createRemoveOwnerTx

Returns the Safe transaction to remove an owner and optionally change the threshold.


_10
const params: RemoveOwnerTxParams = {
_10
ownerAddress,
_10
newThreshold // Optional. If `newThreshold` isn't provided, the current threshold will be decreased by one.
_10
}
_10
const safeTransaction = await protocolKit.createRemoveOwnerTx(params)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createRemoveOwnerTx(params, options)

createSwapOwnerTx

Returns the Safe transaction to replace an owner of the Safe with a new one.


_10
const params: SwapOwnerTxParams = {
_10
oldOwnerAddress,
_10
newOwnerAddress
_10
}
_10
const safeTransaction = await protocolKit.createSwapOwnerTx(params)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createSwapOwnerTx(params, options)

getOwners

Returns the list of Safe owner accounts.


_10
const ownerAddresses = await protocolKit.getOwners()

getOwnersWhoApprovedTx

Returns a list of owners who have approved a specific Safe transaction.


_10
const transactions: MetaTransactionData[] = [{
_10
// ...
_10
}]
_10
const safeTransaction = await protocolKit.createTransaction({ transactions })
_10
const txHash = await protocolKit.getTransactionHash(safeTransaction)
_10
const ownerAddresses = await protocolKit.getOwnersWhoApprovedTx(txHash)

isOwner

Checks if a specific address is an owner of the current Safe.


_10
const isOwner = await protocolKit.isOwner(address)

Threshold

createChangeThresholdTx

Returns the Safe transaction to change the threshold.


_10
const safeTransaction = await protocolKit.createChangeThresholdTx(newThreshold)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createChangeThresholdTx(newThreshold, options)

getThreshold

Returns the Safe threshold.


_10
const threshold = await protocolKit.getThreshold()

Safe Guards

createDisableGuardTx

Returns the Safe transaction to disable a Safe Guard.


_10
const safeTransaction = await protocolKit.createDisableGuardTx()
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createDisableGuardTx(options)

createEnableGuardTx

Returns the Safe transaction to enable a Safe Guard.


_10
const safeTransaction = await protocolKit.createEnableGuardTx(guardAddress)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = {
_10
safeTxGas, // Optional
_10
baseGas, // Optional
_10
gasPrice, // Optional
_10
gasToken, // Optional
_10
refundReceiver, // Optional
_10
nonce // Optional
_10
}
_10
const safeTransaction = await protocolKit.createEnableGuardTx(guardAddress, options)

getGuard

Returns the enabled Safe Guard or 0x address if no guards are enabled.


_10
const guardAddress = await protocolKit.getGuard()

Safe Modules

createDisableModuleTx

Returns a Safe transaction ready to be signed that will disable a Safe Module.


_10
const safeTransaction = await protocolKit.createDisableModuleTx(moduleAddress)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createDisableModuleTx(moduleAddress, options)

createEnableModuleTx

Returns a Safe transaction ready to be signed that will enable a Safe Module.


_10
const safeTransaction = await protocolKit.createEnableModuleTx(moduleAddress)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createEnableModuleTx(moduleAddress, options)

getModules

Returns the list of addresses of all the enabled Safe Modules.


_10
const moduleAddresses = await protocolKit.getModules()

isModuleEnabled

Checks if a specific Safe Module is enabled for the current Safe.


_10
const isEnabled = await protocolKit.isModuleEnabled(moduleAddress)

FallbackHandler

createDisableFallbackHandlerTx

Returns the Safe transaction to disable the fallback handler.


_10
const safeTransaction = await protocolKit.createDisableFallbackHandlerTx()
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = { ... }
_10
const safeTransaction = await protocolKit.createDisableFallbackHandlerTx(options)

createEnableFallbackHandlerTx

Returns the Safe transaction to enable the fallback handler.


_10
const safeTransaction = await protocolKit.createEnableFallbackHandlerTx(fallbackHandlerAddress)
_10
const txResponse = await protocolKit.executeTransaction(safeTransaction)
_10
await txResponse.transactionResponse?.wait()

This method can optionally receive the options parameter:


_10
const options: SafeTransactionOptionalProps = {
_10
safeTxGas, // Optional
_10
baseGas, // Optional
_10
gasPrice, // Optional
_10
gasToken, // Optional
_10
refundReceiver, // Optional
_10
nonce // Optional
_10
}
_10
const safeTransaction = await protocolKit.createEnableFallbackHandlerTx(fallbackHandlerAddress, options)

Messages

createMessage

Returns a SafeMessage ready to be signed by the owners.


_10
const rayMessage: string | EIP712TypedData = "I am the owner of this Safe"
_10
const message = protocolKit.createMessage(rawMessage)

getSafeMessageHash

Retrieve the Safe message hash of a string, or EIP-712 typed data. It produces the identical hash as invoking the CompatibilityFallbackHandler's getMessageHash method.


_10
const rawMessage = ... // String or EIP-712 typed data
_10
const messageHash = hashSafeMessage(rawMessage)
_10
_10
const safeMessageHash = await protocolKit.getSafeMessageHash(messageHash)

isValidSignature

Calls the CompatibilityFallbackHandler isValidSignature method (EIP-1271).

It requires two parameters:

  • messageHash: The hash of the message
  • signature: The signature to be validated or '0x'. You can send as signature one of the following:
    1. An array of SafeSignature. In this case the signatures are concatenated for validation (buildSignatureBytes())
    2. The concatenated signatures as string
    3. '0x' if you want to validate an onchain message (Approved hash)

The method returns if the signature is valid


_10
const rawMessage = ... // String or EIP-712 typed data
_10
const messageHash = hashSafeMessage(rawMessage)
_10
const safeMessageHash = await protocolKit.getSafeMessageHash(messageHash)
_10
_10
const isValidSignature = await protocolKit.isValidSignature(safeMessageHash, signature)
_10
...
_10
const isValidSignature = await protocolKit.isValidSignature(safeMessageHash, [signature1, signature2])
_10
...
_10
const isValidSignature = await protocolKit.isValidSignature(safeMessageHash, '0x')

signMessage

Returns a new SafeMessage object that includes the signature of the current owner.

You can use multiple signing methods, such as:

  • ETH_SIGN (eth_sign): Regular hash signature
  • ETH_SIGN_TYPED_DATA_V4 (eth_signTypedData_v4): Typed data signature v4, The default method if no signing method is passed
  • ETH_SIGN_TYPED_DATA_V3 eth_signTypedData_v3: Typed data signature v3
  • ETH_SIGN_TYPED_DATA eth_signTypedData: Typed data signature
  • SAFE_SIGNATURE: Signing with another Safe contract as signer

The third parameter (optional) is the preImageSafeAddress. If the preimage is required, this is the address of the Safe that will be used to calculate the preimage. It's a mandatory parameter for 1.3.0 and 1.4.1 contract versions. This is because the safe uses the old EIP-1271 interface, which uses bytes instead of bytes32 for the message; we need to use the pre-image of the message to calculate the message hash. This parameter is used in conjunction with the SAFE_SIGNATURE signing method.


_10
const rawMessage: string | EIP712TypedData = "I am the owner of this Safe"
_10
const message = protocolKit.createMessage(rawMessage)
_10
const signedMessage = await protocolKit.signMessage(message)

Optionally, an additional parameter can be passed to specify a different way of signing:


_10
const signedMessage = await protocolKit.signMessage(signedMessage, SigningMethod.ETH_SIGN_TYPED_DATA_V4) // Default option
_10
const signedMessage = await protocolKit.signMessage(signedMessage, SigningMethod.ETH_SIGN)
_10
const signedMessage = await protocolKit.signMessage(signedMessage, SigningMethod.SAFE_SIGNATURE, parentSafeAddress).

Was this page helpful?