An npm package for crafting multi-send transaction from a Gnosis Safe, based on ethers.js.
- Easily encode the most common types of transactions from JSON inputs:
- ETH & ERC20 token transfers
- NFT transfers
- Contract function calls
- Raw transactions
- Encode a batch of transactions into a single multi-send call.
The encode functions produce JavaScript objects that can be used to actually execute the described transactions. There are various ways to do that:
- from any enabled Safe/Zodiac module via
executeTransactionFromModule
(see: Zodiac Module base contract) - directly by calling the Safe's
execTransaction
function, providing the required owner signatures (learn more) - collecting the required signatures on-chain, by calling
approveHash
upfront (learn more) - collecting the required signatures off-chain, by proposing the transaction using the Safe Transaction Service
Check out the @gnosis.pm/safe-core-sdk package for interacting with the Gnosis Safe contracts and the @gnosis.pm/safe-service-client package for using the Safe Transaction Service from JavaScript apps.
This module is distributed via npm. For adding it to your project, run:
npm install --save ethers-multisend
To install it using yarn, run:
yarn add ethers-multisend
encodeSingle(transactionInput: TransactionInput): MetaTransaction
Encodes a single transaction input and turns into an format that is ready for execution.
encodeMulti(
metaTransaction: MetaTransaction[],
multiSendContractAddress?: string
): MetaTransaction
Batches a set of meta transactions into a single multi-send contract call.
decodeSingle(
metaTransaction: MetaTransaction,
provider: Provider,
fetchAbi?: (address: string) => Promise<string | undefined>,
id?: string
): Promise<TransactionInput>
Decodes a meta transaction and returns a transaction input object of one of the four supported types. It needs an ethers provider instance to fetch decimals for ERC20 token transfers, and a function for fetching the ABI for a contract address.
decodeMulti(data: string): MetaTransaction[]
Given the data string of a multi-send transaction, returns an array of the included meta transactions.
createTransaction(type: TransactionType, id?: string): TransactionInput
Creates an empty transaction input of the specified type.
isValid(transactionInput: TransactionInput): boolean
Returns whether the provided transaction input can be encoded into a meta transaction without errors and has a valid to
address.
The TransactionInput
type captures the information for any of the four supported transaction types.
type TransactionInput =
| CallContractTransactionInput
| TransferFundsTransactionInput
| TransferCollectibleTransactionInput
| RawTransactionInput
The library's encoding functions return objects of the MetaTransaction
type, which is a format with an ABI encoded data
field so it is ready for execution.
interface MetaTransaction {
readonly to: string
readonly value: string
readonly data: string
readonly operation?: OperationType
}
Find the full information about all TypeScript types here: src/types.ts