您正在查看: Ethereum-开源推荐 分类下的文章

ethRPCtoREST - 执行层 JSON-RPC API 的 RESTful 接口

如何使用它?

  1. 下载ethRPCtoREST二进制文件,使用 使其可执行chmod +x ./ethRPCtoREST。
  2. 执行它./ethRPCtoREST $RPC_URL。
  3. 您已完成!打开 localhost:3000 并访问端点处可用的API SPEClocalhost:3000/docs中提到的 URL 端点。

github: https://github.com/Amit0617/ethRPCtoREST

用于以太坊 RLP 解码的 Solidity 库

安装

  1. npm install solidity-rlp在项目目录中。请确保通过 npm 安装以便及时更新!
  2. import "solidity-rlp/contracts/RLPReader.sol"在所需的智能合约中。

github: https://github.com/hamdiallam/Solidity-RLP.git

测试例子

import "solidity-rlp/contracts/RLPReader.sol"

contract SomeContract {

    // optional way to attach library functions to these data types.
    using RLPReader for RLPReader.RLPItem;
    using RLPReader for RLPReader.Iterator;
    using RLPReader for bytes;

    // lets assume that rlpBytes is an encoding of [[1, "nested"], 2, 0x<Address>]
    function someFunctionThatTakesAnEncodedItem(bytes memory rlpBytes) public {
        RLPReader.RLPItem[] memory ls = rlpBytes.toRlpItem().toList(); // must convert to an rlpItem first!

        RLPReader.RLPItem memory item = ls[0]; // the encoding of [1, "nested"].
        item.toList()[0].toUint(); // 1
        string(item.toList()[1].toBytes()); // "nested"

        ls[1].toUint(); // 2
        ls[2].toAddress(); // 0x<Address>
    }

    // lets assume rlpBytes is an encoding of [["sublist"]]
    function someFunctionThatDemonstratesIterators(bytes memory rlpBytes) public {
        RLPReader.Iterator memory iter = rlpBytes.toRlpItem().iterator();
        RLPReader.Iterator memory subIter = iter.next().iterator();

        // iter.hasNext() == false
        // string(subIter.next().toBytes()) == "sublist"
        // subIter.hasNext() == false
    }
}

参考

https://ethereum.stackexchange.com/questions/42732/how-to-rlp-encode-messages-in-solidity

以太坊智能合约事件索引器

eth-事件索引器

以太坊智能合约事件索引器

  • 使用 Postgres 数据库 GoEthereum 客户端/SDK 和 Infura 作为节点进行基本智能合约事件索引。

先决条件

  • Infura 帐户(API 密钥、网络端点 WSS/HTTPS)
  • Docker
  • 创建 .env 文件并使用 .env_tmpl 填充配置数据

安装/使用 Docker 运行

在项目文件夹中运行命令:
docker-compose up --build

安装 不使用 Docker 但使用已安装的 Postgress

  • 安装 Go(golang)
  • 从 scripts/db 文件夹运行 psql 脚本
  • 运行命令根项目文件夹
    go run main/main.go

数据库清理

  • 从根项目文件夹中删除“db-data”文件夹

使用方法 - 来自 Postman

  • GET: /api/events/:address
  • GET: /api/indexed/:id
  • POST: /api/events/add/:address