-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom http.Agent / https.Agent support ( Tor, Socks5, various proxy support ) #2829
Conversation
http?: http.Agent; | ||
https?: https.Agent; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is also being used by Web3.js https://github.com/ChainSafe/web3.js/blob/1.x/packages/web3-providers-http/types/index.d.ts#L32 as well as many typescript implementations using http.Agent
.
@@ -81,6 +89,7 @@ export async function getUrl(href: string, options?: Options): Promise<GetUrlRes | |||
|
|||
method: (options.method || "GET"), | |||
headers: shallowCopy(options.headers || { }), | |||
agent: (agent || false), | |||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember that @types/node
checks that this should only be one of the Agent
supported by http
or otherwise it is a boolean.
Hello @ayanamidev, I'm in need for exactly this, so I guess I won't wait for ethers maintainers to merge this - I would like to start using it right now. Not sure about how to add the HTTP agent (in my case, would be a proxy) to ethers - could you document (or link me to the documentation about) how to do so? Thanks again! |
@NBMSacha Actually, it is hard to document how to use the feature without merging this PR since |
Thanks for your reply!! So there is no way I can get started with the codebase from your branch and use an http agent before you find some time to code the standalone version? :/ |
@NBMSacha Can't tell this one would be lighter than the native ethers provider, however, if you would find some temporary workout until the changes are reflected for v6, here is something for you. |
What happened with ethers-axios-provider repository? Was there any issue/security issue with this library? |
Does ethers v6 support custom http proxy now? |
hello, still not implemented in V6? anybody know? |
It’s available. The |
thank you so much! |
@cryptothink629 I have posted the example code which works with V6 #4336 |
fixes #2709, #2775
If you want this feature before this PR is merged, there is a custom, unofficial ethers provider to use right now https://github.com/ayanamitech/ethers-axios-provider
Why adding ability to use custom http.agent / https.agent is important?
One of the missing features of ethers.js compared with web3.js is that injecting http.agent is impossible although the web3.js have been supported using custom http.agent for more than 2 years.
Example: https://web3js.readthedocs.io/en/v1.2.11/include_package-core.html?highlight=agent#configuration
@types/node
definition of RequestOptions which ethers.js use for initiating remote RPC providershttps://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules__types_node_http_d_._http_.requestoptions.html
One of the key features of the ability to inject custom http.agent supports is that it could not only provide essential network connectivity from the censored internet environment but also secures the connection with a secure, private, and faster proxy interface without using VPN.
See also: https://www.coindesk.com/policy/2022/03/03/metamask-infura-block-certain-areas-amid-crypto-sanctions-fury/
Related issues / PR from web3.js
web3/web3.js#887
web3/web3.js#2827
web3/web3.js#2946
web3/web3.js#2980
As you could see, many chinese developers use this feature to evade network firewalls across the border.
Example use case of using web3.js with socks5 proxy ( Tor connection )
Tornado-cli ( Which supports censorship resistant, ip concealing connection with Tor Network )
https://github.com/tornadocash/tornado-cli/blob/master/cli.js#L1205
What does this PR do?
By implementing the minimal interface of
http.agent
which is also compatible with@types/node
package ( as used by ethers.js package ), any RPC provider from ethers.js could provide remote connectivity wrapped by various type of proxies with native way without the need of routing the packets of nodejs or browser workers.Testing this PR
This PR could be tested against various proxy agents, here is the example that connects Infura with Tor Network using the modified local built ethers.js package.
$ git clone -b custom-http-agent-support https://github.com/0xAyanami/ethers.js $ cd ethers.js $ npm i $ npm i --save socks-proxy-agent $ npm run build $ npm i $ nano test.js
and write this file to
test.js
Change the
torPort
value if you are using Tor with service without installing it from Tor Browser,Run
node test.js
to check if it works, also try turning off the Tor to check if theSocksProxyAgent
injected withethers.js
only works with tor connection only.Example output