{"content":{"title":"RPCHub - 推荐一个非常好用的RPC 工具","body":"作为一名 Web3 开发者，你是否遇到这样的问题：MetaMask 配置节点 RPC URL 又连接不上了，需要去[Chainlist](https://chainlist.org/) 或 [Rpclist](https://rpclist.com/)  重新找一个节点配置到MetaMask， 也许过段时间有需要重新做一遍。\r\n\r\n\r\n\r\n如果你有这个困扰，RPCHub 推荐给你，RPCHub 由 BlockPI 团队开发， 我也是从 [Web3极客公开课](https://learnblockchain.cn/course/32) 听到这款产品。\r\n\r\n\r\n\r\nRPCHub 是一款 RPC 聚合器， 是一个在本地运行的软件，MetaMask 配置节点连接到 RPCHub， 然后 RPCHub 将RPC请求分发到多个RPC端点。RPCHub可以同时配置多个端点（可以私有的、公共的节点服务器），另外支持我们自己来配置负载平衡的策略，以确保快速响应时间。\r\n\r\n\r\n\r\n## RPCHub 安装\r\n\r\nRPCHub 是一款开源命令行工具，在GitHub  https://github.com/BlockPILabs/aggregator 下载最新的Releases 版本：\r\n\r\n\r\n\r\n![image-20230603120307251](https://img.learnblockchain.cn/pics/20230603120313.png)\r\n\r\n当前最新的版本是1.0.1 ，我们选择自己的系统进行下载。下载之后解压缩，会包含一个 `aggregator` 可执行文件，直接运行：\r\n\r\n```bash\r\n./aggregator \r\nv1.0.1\r\nEROR[06-03|03:40:11] Load default config failed               module=config statusCode=0 error=timeout retries=1\r\nINFO[06-03|03:40:15] Load default config success              module=config\r\nINFO[06-03|03:40:16] New load balancer                        module=load-balance chain=ethereum-sepolia nodes=1\r\nINFO[06-03|03:40:16] New load balancer                        module=load-balance chain=gnosis nodes=1\r\nINFO[06-03|03:40:16] New load balancer                        module=load-balance chain=oasys nodes=2\r\nINFO[06-03|03:40:16] New load balancer                        module=load-balance chain=scroll-testnet nodes=2\r\n...\r\nINFO[06-03|03:40:23] Updated authority phishing db            module=plugins addresses=2986\r\nINFO[06-03|03:40:23] Starting proxy server                    module=server addr=:8011\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/aptos\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/arbitrum\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/avalanche\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/bsc\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/ethereum\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/ethereum-goerli\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/ethereum-sepolia\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/fantom\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/gnosis\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/optimism\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/polygon\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/polygon-mumbai\r\nINFO[06-03|03:40:23] Registered RPC                           module=server endpoint=http://localhost:8011/scroll-testnet\r\n```\r\n\r\n\r\n\r\n`aggregator`  启动后，会打印差距所有可用的链的RPC (例如：http://localhost:8011/bsc)， 介绍就可以把这个端点配置到MetaMask中， 如图：\r\n\r\n![image-20230603121549078](https://img.learnblockchain.cn/pics/20230603121551.png)\r\n\r\n\r\n\r\n\r\n\r\n## PRCHub 配置\r\n\r\n\r\n\r\nPRCHub 提供了前端Console页面（https://ag-cfg.rpchub.io/）来方便用户配置区块链的RPC 端口。\r\n\r\n打开https://ag-cfg.rpchub.io/， 输入 `http://127.0.0.1:8012`  和密码`123456` ：\r\n\r\n\r\n\r\n![image-20230603124329397](https://img.learnblockchain.cn/pics/20230603124330.png)\r\n\r\n之后就进入了控制台。\r\n\r\n> 其实 RPCHub 的配置是存储在本地的， Console 前端的配置页面会通过访问 RPCHub 启动的 server （http://127.0.0.1:8012）来读取本地配置以及写入新配置。\r\n\r\n\r\n\r\n### 添加 RPC \r\n\r\n![image-20230603123106410](https://img.learnblockchain.cn/pics/20230603123107.png)\r\n\r\n我这里给BSC添加了一个新的 RPC URL：\r\n\r\n![image-20230603123016873](https://img.learnblockchain.cn/pics/20230603123018.png)\r\n\r\n\r\n\r\n随后我们可以在`aggregator` 控制台看到有对新添加节点 `ninicoin` 的请求。\r\n\r\n```bash\r\nDBUG[06-03|04:54:07] relay rpc -> eth_call                    module=plugins sid=s-0000000000000158 node=bsc-blockpi-public isTx=true tries=2\r\nDBUG[06-03|04:54:21] relay rpc -> eth_blockNumber             module=plugins sid=s-0000000000000159 node=bsc-blockpi-public isTx=false tries=1\r\nDBUG[06-03|04:54:21] relay rpc -> eth_getBlockByNumber        module=plugins sid=s-0000000000000160 node=bsc-blockpi-public isTx=false tries=1\r\nDBUG[06-03|04:54:21] relay rpc -> eth_call                    module=plugins sid=s-0000000000000161 node=ninicoin isTx=true tries=1\r\nDBUG[06-03|04:54:41] relay rpc -> eth_blockNumber             module=plugins sid=s-0000000000000162 node=omniatech isTx=false tries=1\r\nDBUG[06-03|04:54:43] relay rpc -> eth_getBlockByNumber        module=plugins sid=s-0000000000000163 node=ninicoin isTx=false tries=1\r\nDBUG[06-03|04:54:46] relay rpc -> eth_getBlockByNumber        module=plugins sid=s-0000000000000163 node=omniatech isTx=false tries=2\r\nDBUG[06-03|04:54:47] relay rpc -> eth_call                    module=plugins sid=s-0000000000000164 node=bsc-official isTx=true tries=1\r\n```\r\n\r\n\r\n\r\n我们还可以根据需要设置代理， 设置钓鱼地址数据库等。\r\n\r\n![image-20230603125817619](https://img.learnblockchain.cn/pics/20230603125818.png)\r\n\r\n\r\n\r\n开发者们如果对 RPCHub 有什么想法，还可以向 [@BlockPI](https://twitter.com/RealBlockPI) 。 \r\n\r\n\r\n\r\n希望 RPCHub 可以帮助到各位 web3 开发者。\r\n\r\n本文来自 [@Tiny熊](https://twitter.com/tinyxiong_eth)  ，[ChainToolDAO](https://chaintool.tech/) 致力于为开发者提供高效、易用、开源的区块链开发工具。"},"author":{"user":"https://learnblockchain.cn/people/14456","address":null},"history":"QmbKnDBBk3p7T3mbcUvBwTsQ4UhV6z82adSoGEBx6cd5rb","timestamp":1685769996,"version":1}