'BSC Testnet: Truffle Migrate ETIMEDOUT

I need to deploy my smart contract to BSC Testnet

I always got this :

Error: PollingBlockTracker - encountered an error while attempting to update latest block:
Error: ETIMEDOUT

I tried to change the RPC specified here https://docs.binance.org/smart-chain/developer/rpc.html#rate-limit

All of them, yet still the same.

One thing is, I tried to deploy it to ropsten instead just for fun. And it is success. Is there any problem with BSC Testnet RPC nowadays ?

Here is my snip for truffle-config.js

        testnet: {
            provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-1-s2.binance.org:8545`),
            network_id: 97, // 3 for ropsten, 97 for bsc test
            confirmations: 2,
            timeoutBlocks: 2000,
            skipDryRun: true,
            networkCheckTimeout: 1000000
        },

I searched, some people use websocket (wss), some change the RPC Url, some add the networkCheckTimeout. I tried all of them (except wss, since I don't see it is provided by BSC Testnet). But nothing work.

Any suggestion ? Thank you



Solution 1:[1]

When I used other endpoints, The issue was fixed. You can try the below endpoints.

BSC RPC Endpoints:

https://data-seed-prebsc-1-s1.binance.org:8545/
https://data-seed-prebsc-2-s1.binance.org:8545/
https://data-seed-prebsc-1-s2.binance.org:8545/
https://data-seed-prebsc-2-s2.binance.org:8545/
https://data-seed-prebsc-1-s3.binance.org:8545/
https://data-seed-prebsc-2-s3.binance.org:8545/

Solution 2:[2]

bsc: {
  networkCheckTimeout: 999999,
  provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-1-s1.binance.org:8545`),
  network_id: 97, // Ropsten's id
  gas: 5500000, // Ropsten has a lower block limit than mainnet
  confirmations: 10, // # of confs to wait between deployments. (default: 0)
  timeoutBlocks: 200, // # of blocks before a deployment times out  (minimum/default: 50)
  skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
},

adding network timeout should help

Solution 3:[3]

The problem is that BSC produces blocks so quickly that it exceeds the default number of blocks Truffle is configured to wait for. You can solve this by adding the networkCheckTimeout and timeoutBlocks fields in your network config:

bsc: {
  networkCheckTimeout: 1000000,
  timeoutBlocks: 200
}

Solution 4:[4]

I searched for more than a week. Finally, I found the answer here, Not only change the pollingInterval, but also do this: in the module web3-provider-engine? modify the timeout a bigger number. Remember that, the module maybe imported more than one times, so change the value everywhere in your projects.

xhr({
    uri: targetUrl,
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(newPayload),
    rejectUnauthorized: false,
    timeout: 2000,  // change the value bigger

The timeout value is hardcoded, maybe nowadays most people have very good Internet connection and only a few techs suffering, I tried very hard to find out the answer. After I change this configuration, I never suffer timeout!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Milad Jafari
Solution 2 eMiracle
Solution 3 Paul Razvan Berg
Solution 4 gfan