truffle icon indicating copy to clipboard operation
truffle copied to clipboard

Truffle doesn't support ethers.js providers

Open its-everdred opened this issue 3 years ago • 8 comments

Issue

In my truffle.config, I should be able to use an ethers provider and signer when I initialize a network.

Steps to Reproduce

  1. Try returning an ethers provider directly:
const ethers = require("ethers");

module.exports = {
  networks: {
    kovan: {
      provider: function () {
        const l1Provider = new ethers.providers.JsonRpcProvider("https://kovan.infura.io/ws/v3/" + infuraKey); 
        const wallet = ethers.Wallet.fromMnemonic(kovanMnemonic);
        const l1Signer = wallet.connect(l1Provider);
        return l1Provider;
      }
  1. Try returning an HDWalletProvider given an ether's provider:
const ethers = require("ethers");

module.exports = {
  networks: {
    kovan: {
      provider: function () {
        const l1Provider = new ethers.providers.JsonRpcProvider("https://kovan.infura.io/ws/v3/" + infuraKey); 

        return new HDWalletProvider(
          { mnemonic: kovanMnemonic, providerOrUrl: l1Provider }
        );

Expected Behavior

The provider should be initialized.

Actual Results

UnhandledRejections detected
Promise {
  <rejected> 
    ...
    reason: 'bad response',
    code: 'SERVER_ERROR',
    status: 400,
    headers: ...,
    body: '{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid json request"}}',
    requestBody: '{"method":{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[],"skipCache":true},"id":43,"jsonrpc":"2.0"}',
    requestMethod: 'POST',
    url: 'https://kovan.infura.io/v3/...'

Environment

  • Operating System:
  • Ethereum client:
  • Truffle version (truffle version): v5.5.13
  • Ganache v^7.1.0
  • node version (node --version): 14.18.0
  • npm version (npm --version): 8.5.0

its-everdred avatar May 24 '22 22:05 its-everdred

Worth noting: Ethers's notion of a "provider" is a bit different from web3's. Web3 has a separation between the provider, which provides the low-level interface, and the web3 object, which provides the high-level interface on top of it. Ethers doesn't have this separation; its "provider" objects provide both the high-level and the low-level interface. And obviously that interface is a bit different. So, this should be quite doable, but watch out for the differences!

haltman-at avatar May 26 '22 17:05 haltman-at

On top of the "provider" equivocation @haltman-at mentioned, here's the web3 => ethers migration guide.

cliffoo avatar May 26 '22 18:05 cliffoo

I am assuming that this is being worked on internally?

swisstackle avatar Jun 04 '22 16:06 swisstackle

@swisstackle Not yet! Are you interested in working on this? We haven't analyzed this task in its entirety to figure out exactly what this will entail yet.

eggplantzzz avatar Jun 07 '22 17:06 eggplantzzz

@eggplantzzz Yes. I think it will be a decent challenge for me as I am not familiar with ethers.js yet but Id love to get involved. I can start working in this tomorrow.

swisstackle avatar Jun 07 '22 17:06 swisstackle

Thank you for your interest @swisstackle! I plan to look into this a bit next week. Let me know if you've researched it at all, otherwise I'll report back here with my findings.

its-everdred avatar Jul 07 '22 21:07 its-everdred

@kevinweaver You can report back with your findings as I first have to finish the other feature Im working on for truffle. Im looking forward to help with this though.

swisstackle avatar Jul 07 '22 21:07 swisstackle

I spiked on this this issue for a some time, but have to leave it as it. In an attempt to capture my findings, I put together this research doc: https://hackmd.io/bncUOJIFSMmFp9qGVVdgbg and a branch: add-ethers-provider-support

There’s not much of value in that branch, I mainly used it to poke around while I was learning what does what. That doc holds more of my learnings.

To anyone that picks up this work, start by following the reproduction steps in that issue, pull down ethers locally and point your local truffle to it to help you triangulate where the request is timing out.

That will probably point you toward setting up the new /interface-adapter/lib/adapter/ethers/index.ts file that I discuss in the research doc.

🫡

its-everdred avatar Sep 09 '22 00:09 its-everdred

@benjamincburns are you the keeper of the current status of this issue? any latest updates on it? thanks!

gnidan avatar Sep 29 '22 18:09 gnidan

New keeper of the current status is @gnidan. @benjamincburns if you are available before this gets done @gnidan welcomes your assistance.

davidmurdoch avatar Oct 27 '22 18:10 davidmurdoch

Since this issue is specifically about using Ethers.js providers in truffle-config.js, I think we can close this as won't fix. It's not clear that there's value in supporting this, since the work to instantiate an Ethers provider in config is not any easier or less overhead than just following Truffle's own provider configuration patterns.

Leaving #5947 in this issue's place, to cover the more useful case of using Ethers.js other abstractions in tests and scripts.

gnidan avatar Mar 02 '23 19:03 gnidan