ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.97k stars 1.85k forks source link

Meta transaction (a.k.a. Gasless transactions) using ethers.js #619

Closed digvjs closed 4 years ago

digvjs commented 5 years ago

Is there a way to implement a meta transaction using ethers.js library.

Consider a transaction to transfer 100 tokens from 0xAccountA to 0xAccountB. The transaction will be signed by 0xAccountA but the gas would be payed by some other 0xAccountC.

ricmoo commented 5 years ago

I have not actually used Meta-transactions yet, but all the necessary functions should certainly be available. I will be bugging the metatx cartel during DevCon5 to get caught up on the latest techniques. :)

digvjs commented 5 years ago

I have not actually used Meta-transactions yet, but all the necessary functions should certainly be available. I will be bugging the metatx cartel during DevCon5 to get caught up on the latest techniques. :)

Is there any discussion channel such for this thing?

ricmoo commented 5 years ago

There may be an ETH Magicians event for it, otherwise I'm sure they will post something. I just haven't had time to look into it yet. Feel free to look it up and let me know. ;)

Amxx commented 5 years ago

Each wallet has it's own meta-transaction format & signature. So I don't really think there is a "generic" way for ethers to support meta-tx. However, ethers can (and is already) used to build wallet specific tolling. For exemple, this is my SDK for doing metatransaction with (my) KitsuneWallets:

ricmoo commented 5 years ago

Awesome, thanks! I’ll look into that.

I thought the meta-ts cartel was trying to create a standard so that relay networks (or whatever they are called) can be used as a market to make meta-tax reliable... I honesty haven’t looked into it enough though since the eth magicians last DevCon...

Amxx commented 5 years ago

More and more people are moving away from the relay gas network due to it's (many) limitations. Universal Login (for one) is not compatible (that I'm sure of) ... I also suspect argent/other to not be compatible. I'll be in Devcon, reach me @amxx (ethereum-magicians / twitter) if you want to discuss that

marcelomorgado commented 5 years ago

I think it's related to https://github.com/OpenZeppelin/openzeppelin-gsn-provider

ricmoo commented 4 years ago

I'm going to track this (GSN and meta-transactions in general) in #636, so I'll close this issue.

@yuetloo has started looking into it and figuring out how to create a GsnSigner. :)

joeb000 commented 4 years ago

@ricmoo just FYI I am working on extending ethers.js to add an intuitive way for Dapp devs to integrate meta transactions into their dapp with only a couple lines of code.

I am imagining something like this:

    const metaConfig = {
        relayerURL: "https://somerelayernode.com",
        metaType: "erc1776" // metamask Generalized MetaTransaction Contest winner: https://github.com/wighawag/singleton-1776-meta-transaction
    }
    const metaSigner = provider.getMetaSigner(metaConfig)
    const metaContract = new ethers.MetaContract(address, abi, metaSigner)

    // call it just like you would with a normal ethers contract
    let metaTx = await metaContract.someFunction(param1, param2)

Basically allow dapp devs using ethers to set their relayer and metaType in a config object and initialize a MetaSigner (extension of Signer) which instead of signing a transaction and POSTing to the Provider's URL, it will sign a meta transaction (in the above example with signTypedData_v4) and send the signed meta transaction hex string to the relayerURL.

To pilot this concept I extended ethers.js with my own meta-ethers library and used my own simplified meta transaction schema. My experiments have gone very well, so I am now working on forking ethers.js base code to build this functionality into the native ethers.js source code itself. Will post back here when I have anything worthy of review/beta testing.

holgerd77 commented 4 years ago

Can't this be done in a more modular/plugin-like way? Also question for @ricmoo

ricmoo commented 4 years ago

I don't know how those last few comments slipped past me...

@yuetloo has a working GsnSigner, which is just another normal ethers Signer, there shouldn't be any need to fork ethers.Basically, you instantiate a GsnSigner and just use ethers normally, except all transactions just happen over the GSN, no additional changes are needed by users.

I haven't had a chance to do the code review yet, but she her fork and changes are available. :)

This will be added to the experimental package at first, until it is stable, but yes this would eventually be its own sub-package, or may be bundled with similar Signers, but will be under a @ethersproject/ package in the packages/ folder.