Coder Social home page Coder Social logo

gnosisguild / ethers-multisend Goto Github PK

View Code? Open in Web Editor NEW
63.0 6.0 8.0 271 KB

An npm package for crafting multi-send transaction from a Zodiac Avatar, such as a Gnosis Safe, based on ethers.js

License: GNU Lesser General Public License v3.0

TypeScript 82.24% Solidity 17.76%
typescript ethereum gnosis-safe zodiac ethersjs

ethers-multisend's Introduction

ethers-multisend

Build Status Contributor Covenant

An npm package for crafting multi-send transaction from a Gnosis Safe, based on ethers.js.

Features

  • 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.

What to do with the encoded transaction objects?

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.

Installation

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

API

encodeSingle

encodeSingle(transactionInput: TransactionInput): MetaTransaction

Encodes a single transaction input and turns into an format that is ready for execution.

encodeMulti

encodeMulti(
  metaTransaction: MetaTransaction[], 
  multiSendContractAddress?: string
): MetaTransaction

Batches a set of meta transactions into a single multi-send contract call.

decodeSingle

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

decodeMulti(data: string): MetaTransaction[]

Given the data string of a multi-send transaction, returns an array of the included meta transactions.

createTransaction

createTransaction(type: TransactionType, id?: string): TransactionInput

Creates an empty transaction input of the specified type.

isValid

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.

Types

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

ethers-multisend's People

Contributors

auryn-macmillan avatar jfschwarz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ethers-multisend's Issues

docs: set custom multisend contract address

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots / logs
If applicable, add screenshots and/or logs to help explain your problem.

Relevant environment details:

  • OS: [e.g. iOS]
  • Browser [e.g. chrome 22, safari]
  • Node version [e.g. 14.17.4]
  • etc

Additional context
Add any other context about the problem here.

[Question] Is it possible use MultiSend contract by simple (Externally Owned Accounts) wallet?

I want to send ETH and ERC20 tokens to multiple addresses without any contracts between EOA and Multisend.sol

I've removed next line from MiltiSend.sol

require(address(this) != multisendSingleton, "MultiSend should only be called via delegatecall"); */

and tried to run the next test

    it.only('should encode multiple ETH transfer transactions', async () => {
        const transactions = [
            {
                to: firstRecipient.address,
                value: BigNumber.from(10).pow(18).toString(),
                data: '0x00',
            },
            {
                to: secondRecipient.address,
                value: BigNumber.from(10).pow(18).mul(2).toString(),
                data: '0x00',
            },
        ]
        const multiSendTx = encodeMulti(
            transactions,
            multiSendContract.address
        )

        await multiSendContract.multiSend(multiSendTx.data).then((tx) => tx.wait());

Unfortunately, It doesn't work
Error: Transaction reverted without a reason string

Do you have any ideas? Is it even possible?

Thank you for your attention

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.