BCSkill (Block chain skill )
区块链中文技术社区

只讨论区块链底层技术
遵守一切相关法律政策!

eRPC — 容错 evm rpc 代理

介绍

eRPC 是一种容错 EVM RPC 代理和永久缓存解决方案。它在构建时充分考虑了读取密集型用例,例如数据索引和高负载前端使用。

doc: https://docs.erpc.cloud/
github: https://github.com/erpc/erpc

ethereum beaconchain 轻量级区块浏览器

github: https://github.com/ethpandaops/dora
用例:https://beaconlight.ephemery.dev/

相比https://github.com/gobitfly/eth2-beaconchain-explorer 要简洁很多

w3: 增强以太坊与 Go 的集成

w3是您使用 Go 与以太坊集成的工具带。go‑ethereum它与 紧密相关,为使用RPC、ABI和EVM提供了一个符合人体工程学的包装器。

概览

  • 用于w3.Client连接到 RPC 端点。客户端支持批量请求,请求速度最高可提高 80 倍,并且易于扩展。了解更多
  • 用于w3vm.VM模拟 EVM 执行(可选跟踪和主网状态分叉),或测试智能合约。了解更多
  • 使用w3.Func和w3.Event从 Solidity 函数和事件签名创建 ABI 绑定。了解更多
  • 使用w3.A、w3.H和许多其他实用函数从字符串中解析地址、哈希值和其他常见类型。了解更多

github: https://github.com/lmittmann/w3

代码解析

w3的批量请求

// 1. Connect to an RPC endpoint
client, err := w3.Dial("https://rpc.ankr.com/eth")
if err != nil {
    // handle error
}
defer client.Close()

// 2. Make a batch request
var (
    balance *big.Int
    nonce   uint64
)
if err := client.Call(
    eth.Balance(addr, nil).Returns(&balance),
    eth.Nonce(addr, nil).Returns(&nonce),
); err != nil {
    // handle error
}

是通过使用CallCtx

func (c *Client) CallCtx(ctx context.Context, calls ...w3types.RPCCaller) error {
    // no requests = nothing to do
    if len(calls) <= 0 {
        return nil
    }

    // create requests
    batchElems := make([]rpc.BatchElem, len(calls))
    var err error
    for i, req := range calls {
        batchElems[i], err = req.CreateRequest()
        if err != nil {
            return err
        }
    }

    // invoke rate limiter
    if err := c.rateLimit(ctx, batchElems); err != nil {
        return err
    }

    // do requests
    if len(batchElems) > 1 {
        // batch requests if >1 request
        err = c.client.BatchCallContext(ctx, batchElems)
        if err != nil {
            return err
        }
    } else {

调用go-ethereum->BatchCallContext 实现的

对于我们常规代码实现中,也可以参考实现

基于JWT 身份验证实现以太坊RPC速率受限的 API 网关

概述

该项目是一个用 Go 语言构建的 API 网关,位于去中心化应用程序 (dApp) 的前端,管理对各种区块链网络的请求,目前支持以太坊和 Polygon。它包括基于 JWT 的身份验证、速率限制以及获取最新区块链区块编号的功能。

特征

  • JWT 身份验证:使用 JSON Web 令牌 (JWT) 保护 API。
  • 速率限制:限制客户端可以发出的请求数量,以防止滥用。
  • 区块链网络集成:将请求路由到以太坊和 Polygon 网络以获取最新的区块编号。
  • 模块化中间件设计:可轻松扩展其他中间件或区块链网络。

github: https://github.com/DamianFigiel/api-gateway-dapps-go

GasWait 是一个允许用户选择提交交易的理想时间的工具

GasWait 是一个允许用户选择提交交易的理想时间的工具,通过在网络费用较低时提交来帮助用户节省 gas 费用。

特征

  • 选择交易时间:用户可以选择何时提交交易,避开高昂的 gas 费用时期。
  • 智能 Gas 费用检测:GasWait 会在用户选择的时间范围内自动监控 Gas 费用。
  • 自动提交交易:一旦 gas 费用达到用户期望的水平,GasWait 就会自动提交交易,确保节省成本。

使用案例

  • 想要避免在网络拥塞期间提交交易的用户。
  • 喜欢在 Gas 费用较低时自动提交交易的用户。

亮点

  • 节省 Gas 费:通过等待最佳时间,用户可以显著降低 Gas 成本。
  • 易于使用:用户只需选择他们想要的交易时间,GasWait 会自动处理其余部分。
  • 自动化:系统自动监控并提交交易,无需用户持续监督。

github: https://github.com/Unblock-Chain/eth-gas-wait