繁体   English   中英

调用智能合约方法时如何摆脱 web3 上的 504 超时错误?

[英]How can I get rid of 504 timeout error on web3 when calling a smart contract method?

我不知道该怎么做,我这样做增加了超时

var options = {
    timeout: 60000 * 2, // ms
    // Enable auto reconnection
    reconnect: {
        auto: true,
        delay: 5000, // ms
        maxAttempts: 5,
        onTimeout: false
    }
};
const web3 = new Web3( new Web3.providers.HttpProvider(web3Settings.provider, options));

但有时在调用合约函数时我仍然会收到 504 超时错误

2022-02-16T08:19:00.456908+00:00 app[web.1]: (node:22) UnhandledPromiseRejectionWarning: Error: Invalid JSON RPC response: "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n</body>\r\n</html>\r\n"
2022-02-16T08:19:00.456917+00:00 app[web.1]: at Object.InvalidResponse (/app/node_modules/web3-core-helpers/lib/errors.js:43:16)
2022-02-16T08:19:00.456918+00:00 app[web.1]: at XMLHttpRequest.request.onreadystatechange (/app/node_modules/web3-providers-http/lib/index.js:95:32)
2022-02-16T08:19:00.456918+00:00 app[web.1]: at XMLHttpRequestEventTarget.dispatchEvent (/app/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
2022-02-16T08:19:00.456919+00:00 app[web.1]: at XMLHttpRequest._setReadyState (/app/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
2022-02-16T08:19:00.456919+00:00 app[web.1]: at XMLHttpRequest._onHttpResponseEnd (/app/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
2022-02-16T08:19:00.456919+00:00 app[web.1]: at IncomingMessage.<anonymous> (/app/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)

我正在使用 bsc 测试网网络。

如果您在前端,我们应该使用

new Web3(window.ethereum);
await window.ethereum.enable();

如果您在后端,那么使用它们 HttpProvider 是一个不错的选择。

你可以做一些事情:

  • 确保您使用的 rpc 有效。 可能是指向错误的地址。
  • 尝试与另一个 SC 交互以查看代码是否有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM