trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.32k forks source link

Update documentation for Infura API v3 #1874

Closed jamesmorgan closed 1 year ago

jamesmorgan commented 5 years ago

Issue

Today, when deploying contracts to mainnet I have received the following error whilst using truffle deploy Error: legacy access request rate exceeded

Steps to Reproduce

Deploy a new contract to main.

Expected Behavior

No exceptions

Actual Results

Sample stack trace I get:

   ⠋ Blocks: 29           Seconds: 340Error: legacy access request rate exceeded
    at /Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/web3-provider-engine/subproviders/provider.js:18:1
    at e.callback [as onreadystatechange] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/web3/node_modules/web3-providers-http/src/index.js:96:1)
    at e.call [as dispatchEvent] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at e.dispatchEvent [as _setReadyState] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
    at e._setReadyState [as _onHttpResponseEnd] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)
    at IncomingMessage._onHttpResponseEnd (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
   ⠸ Blocks: 41           Seconds: 528Error: legacy access request rate exceeded
    at /Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/web3-provider-engine/subproviders/provider.js:18:1
    at e.callback [as onreadystatechange] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/web3/node_modules/web3-providers-http/src/index.js:96:1)
    at e.call [as dispatchEvent] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at e.dispatchEvent [as _setReadyState] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
    at e._setReadyState [as _onHttpResponseEnd] (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)
    at IncomingMessage._onHttpResponseEnd (/Users/jamesmorgan/Dropbox/workspace-blockrocket/blockcities/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/fainashalts/truffle-dev/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
   ⠸ Blocks: 46           Seconds: 624^C

Environment

jamesmorgan commented 5 years ago

TBH - looking at this again I guess it may be a HD wallet issue?

eggplantzzz commented 5 years ago

@jamesmorgan Can you give some more details about what you were doing so we can try and reproduce/troubleshoot the problem? What version of Truffle are you using? I assume you are not using the most recent version as you need to be using a version of node >= 8.9.4. Consider upgrading the most recent version of Truffle (and a more recent version of node :) ).

jamesmorgan commented 5 years ago

Ah ye, sorry I copy pasted into the wrong bit, this is my output, I am using a new version of truffle:

truffle version
Truffle v5.0.5 (core: 5.0.5)
Solidity v0.5.0 (solc-js)
Node v8.9.4

I was just deploying several fairly large contracts to mainnet from truffle - this is the command I used, I had 4 migrations to run in total truffle compile; truffle migrate --network live;

live is an option in my truffle config which looks like this:

live: {
            provider: function () {
                return new HDWalletProvider(process.env.MNEMONIC, `https://mainnet.infura.io/v3/${process.env.INFURA_KEY}`);
            },
            network_id: 1,
            gas: 6075039,
            gasPrice: 7000000000,
            timeoutBlocks: 200,
            skipDryRun: true
        },

I have been using truffle for a long time and have never seen this message so thought I would raise it.

eggplantzzz commented 5 years ago

@jamesmorgan I'm not familiar with this error either. Is your codebase available somewhere?

eggplantzzz commented 5 years ago

@jamesmorgan By the way, are you using a legacy infura endpoint? Sounds like it could be the result of you not using the new format? Let me know.

jamesmorgan commented 5 years ago

@eggplantzzz nope I was using the V3 endpoint and I havent seen the error since reporting this. Maybe it was a networking issue which surfaced as the error?

eggplantzzz commented 5 years ago

Huh, very weird. Well I guess it is nice when problems seem to fix themselves. Maybe it was just an infura blip or something. Closing this for now, if it surfaces again feel free to open another!

yuwiggin commented 5 years ago

I had the same issue when deploy a contract on Rinkeby network, although the contract was deployed successfully.

Error: legacy access request rate exceeded
    at /Users/viking/ethereum/project/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/web3-provider-engine/subproviders/provider.js:18:1

How to fix it? Here is a part of truffle.js:

        rinkeby: {
            provider: () =>
                new HDWalletProvider(mnemonic,"https://rinkeby.infura.io/v3/"+PROJECT_ID, 2),
            network_id: 4,
            gas:  6e6,
            gasPrice: 2e9,
        },

Operating System: OXS Ethereum client: Truffle/Infura Truffle v5.0.27 node: v8.15.1 Solidity v0.5.11 (solc-js)

yuwiggin commented 5 years ago

I had the same issue when deploy a contract on Rinkeby network.

Error: legacy access request rate exceeded
    at /Users/viking/ethereum/project/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/gnidan/src/work/truffle/node_modules/web3-provider-engine/subproviders/provider.js:18:1

How to fix it? here is a part of truffle.js

        rinkeby: {
            provider: () =>
                new HDWalletProvider(mnemonic,"https://rinkeby.infura.io/v3/"+PROJECT_ID, 2),
            network_id: 4,
            gas:  6e6,
            gasPrice: 2e9,
        },

Operating System: OXS Ethereum client: Truffle/Infura Truffle v5.0.27 node: v8.15.1 Solidity v0.5.11 (solc-js)

guix77 commented 5 years ago

I’m also having this problem with truffle migrate using latest Truffle 5.1.0

const HDWalletProvider = require('@truffle/hdwallet-provider')

module.exports = {
  networks: {
    ropsten: {
      provider: new HDWalletProvider(process.env.MNEMONIC, 'https://ropsten.infura.io/v3/' + process.env.INFURA_PROJECT_ID),
      gas: 4700000,
      network_id: 3
    },
  },
  migrations_directory: './migrations',
};
CruzMolina commented 5 years ago

Hi @guix77, can you confirm that your Infura Project is set to use Project IDs? (See https://community.infura.io/t/legacy-key-deprecation/443)

Based on your code snippet it looks it already uses Project IDs, but wanted to double-check. 🙂

guix77 commented 4 years ago

Hi @CruzMolina, yes I set up a project in my Infura account, and in my .env I have :

INFURA_PROJECT_ID=abcd...

I tried with "" too and with wss:// but this one does not seem to be implemented.

Furthermore on my Infura account I can see my amount of requests attached to this project.

The error is consistently :

⠼ Saving migration to chain.Error: legacy access request rate exceeded
    at /home/guix/dev/my-smart-contracts/node_modules/web3-provider-engine/subproviders/provider.js:18:36
    at XMLHttpRequest.request.onreadystatechange (/home/guix/dev/my-smart-contracts/node_modules/@truffle/hdwallet-provider/node_modules/web3-providers-http/src/index.js:102:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/guix/dev/my-smart-contracts/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest._setReadyState (/home/guix/dev/my-smart-contracts/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
    at XMLHttpRequest._onHttpResponseEnd (/home/guix/dev/my-smart-contracts/node_modules/xhr2-cookies/xml-http-request.ts:345:8)
    at IncomingMessage.<anonymous> (/home/guix/dev/my-smart-contracts/node_modules/xhr2-cookies/xml-http-request.ts:311:39)
    at IncomingMessage.emit (events.js:198:15)
    at endReadableNT (_stream_readable.js:1139:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:17)
eggplantzzz commented 4 years ago

Hey @guix77, two things that come to mind:

In some cases not having the provider be a function causes issues (though I forget exactly what the conditions are!). So your network config should look something like

  ropsten: {
    provider: function() {
      return new HDWalletProvider(....blah blah....);
    },
    network_id: 3,
    etc.....

Oh, and also make sure you are using the most current version of HDWalletProvider. Let me know if you have any success!

pepihasenfuss commented 4 years ago

I did get the same error message and switched my web3.js dapp towards v3 while generating a fresh API-ID. Then it worked for me. BTW, I did slow down the firing of requests towards Infura. It also helped. It seems that Infura load-balancing or some sort of middleware takes a bit of time between different calls. After a deployment of a contract, e.g., I really need to wait a bit (for confirmations) before I can access the contract and fire read/get calls. A locally running node is always more responsive and produces less error messages.

gnidan commented 4 years ago

Thanks for the confirmation @pepihasenfuss that v3+fresh ID works.

I'll leave this open because it sounds like there's documentation to improve on our side. Can others confirm that @pepihasenfuss's fix works?

Would love this to stop being a source of confusion.

lsqproduction commented 1 year ago

Closing for issue maintenance. It's been fixed in the Truffle boilerplate projects as well as the Truffle suite website.