ETH 中继接口

资讯 2024-06-24 阅读:112 评论:0
在中继开发中,事件的监听是开发难度...
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
 

在这里插入图片描述

insert picture description

在中继开发中,事件的监听是开发难度最高的。
事件监听的技术原理主要是通过获取一个区块内部的交易信息并解析交易信息内的“EventLog”(日志事件)来达到目的。
目前ETH提供web.js库,该库中有区块事件监听函数,但并不完美,有以下不足:

xff0c; event listening is the most difficult to develop.
event listening technical principles are primarily achieved by obtaining transactional information inside a block and dissecting “EventLog” (log event) in the transaction information.
Currently ETH provides web.js library, there is block event listening function xff0c; but not perfect xff0c; xff1a below;

  1. 如果客户端的进程被杀死,监听动作就会被丢失
  2. 如果对上一次最后遍历成功的区块号进行存储,重新启动的时候将会造成时间段内新生成的区块的数据丢失
  3. 完整的监听流程比较消耗客户端的设备资源,影响用户体验

为什么要监听?
中心化Exchange就要做这样的事情,比如充值或者提现,都需要对链上的数据进行监控,要链上转账成功后,再修改中心化服务端的数据库,如果不监控,就提现而言,如果链上交易失败,但是用户在中心化的数值减少了,就会有问题。

Why do you want to listen to xff1f;
centralised Exchange do something like this xff0c; e.g. charge value or withdrawal xff0c; all need to monitor data on the chain xff0c; xff0c after successful transfer on the chain; remodify the central service's database xff0c; if not monitor xff0c; xff0c; if transactions fail on the chain xff0c; but the user's centralized values are reduced xff0c; there are problems.

在ETH机制中,链上的授权,交易,合约发布等事件都是一条条的交易信息,可以把每一笔交易信息提取出来,进行划分处理,就可以实现不同的功能和业务。

In the ETH mechanism xff0c; authorization on the chain xff0c; transaction xff0c; events such as contract publication are a single transaction information xff0c; each transaction information can be extracted xff0c; division processing xff0c; different functions and operations can be achieved.

在这里插入图片描述

insert picture description

RPC接口在基于通讯协议方面有多种实现方法,但是主要是如下两种:

RPC interfaces have a variety of methods of realization based on communication agreements xff0c; however, mainly two xff1a, as follows;

  1. 同“RESTful API”一样,基于应用层HTTP/HTTPS协议实现
  2. 基于传输层的TCP协议实现,也被称为Socket(嵌套字)的实现

两种方式的区别在于请求和响应的位置,一个是在应用层,一个是在传输层。
RPC接口和“RESTful API”接口,在HTTP/HTTPS协议实现,在速度方面几乎没有差别,
但是基于传输层的TCP协议实现的RPC接口,除了数据传输流的层级上比"RESTful"接口少而整体比它快外,传输时的整体数据报层面还少了HTTP/HTTPS的头部数据量及组装的时间损耗。也即是说,当RPC接口基于传输层的TCP协议实现时,RPC接口不仅请求和响应的速度比“RESTful”接口快,而且数据量也相对要少。

The difference between the location of the request and the response xff0c; one in the application layer xff0c; one in the transmission layer.
RPC interface and `RESTful API' interface xff0c; xff0c under the HTTP/HTTPS protocol; little difference in speed xff0c; br/>but RPC interface xff0c under the TCP agreement based on the transmission layer; 34 over the transmission stream; Tuxul34; less interfaces in whole than it does xff0c; less HTTP/HTPS head data volume and time loss for assembly at the transmission level; and less data than #xff0.

常见的RPC框架有以下几种:

The following are common RPC frames: xff1a;

  1. JSON-RPC
  2. XML-RPC
  3. Protobuf-RPC
  4. SOAP-RPC

简言之:RPC协议,就是规范了一种客户端和实现了RPC接口的服务端交互的数据格式。

In short, xff1a; RPC Protocol xff0c; is a data format that regulates an interface between the client and the service that achieves the RPC interface.

RPC接口实现的大致流程:

The approximate process achieved by the RPC interface & #xff1a;

  1. 服务调用方案按照规范好了的编码方式把某个RPC接口的函数和参数进行序列化编码
  2. 发送到服务的提供方,即服务器端
  3. 服务器端再通过反序列化后把对应的参数提取出来
  4. 然后通过调用相关函数
  5. 最后把结果返回给服务端的调用方

在了解ETH RPC接口之前,先了解3个参数,因为这3个参数会出现在每一个接口中。

Before understanding the ETHRPC interface & #xff0c; understanding three parameters & #xff0c; these three parameters appear in each interface.

  • genesis,代表的是最早的,早期的源码版本中等同于 earliest
  • pending,代表的是等待或者挂起状态中的
  • latest,代表的是最新完成的
1.eth_blockNumber

该接口可以根据传参(genesis,pending,latest)获取 3 种类型的区块高度

This interface can capture the height of three types of blocks by reference (genesis,pending,latest)

  1. genesis, 代表的是创世区块,因为可以指定最早的区块号,所以创世区块不一定是0
  2. pending,代表的是当前正在被minter开采的区块,代表正在打包交易的区块,一个区块在打包完一定的交易后才会完整上链
  3. latest,当前链上最新生成的区块的高度
2.eth_getBlockByNumber

该接口根据区块高度获取区块的部分信息,是在遍历区块时主要用来获取区块数据信息的一个接口。该接口可以提供如下数据:

The interface captures parts of block information according to block height & #xff0c; it is an interface that is used mainly to obtain block data information when crossing blocks. The interface provides the following data & #xff1a;

  1. 区块头部的部分字段
  2. 所有打包在这个区块中的交易hash数组

也就是说,返回的数据的结构体是Block,即这个结构体所含有的信息,都可以拿得到。

That is xff0c; the structure of the returned data is Blockxff0c; that is, the information contained in this structure xff0c; is available.

 
3.eth_getTransactionByHash

该接口可以根据一笔交易记录的哈希值,可以获取这笔交易的详细信息。
该接口提供了交易查询功能,在获取交易区块信息后,从区块信息中获取被打包的交易的哈希值,进行全部交易信息的提取。处于pending(等待或者挂起)状态的交易,返回的将会是空,也可以根据接口的这一特点来判断一笔交易是否成功。
获取数据的结构体是Transaction。

The interface can be derived from the Hashi value of a transaction xff0c; details of the transaction can be obtained.
The interface provides a transaction query function xff0c; xff0c after obtaining block information; xff0c when obtaining packaged transactions xff0c from block information; and extracts all transaction information. Transactions in pending (waiting or hanging up) xff0c; returns will be empty xff0c; a transaction can also be judged to be successful on the basis of this feature of the interface.
The structure for obtaining the data is Transaction.

 
4.eth_getTransactionReceipt

该接口可以根据一个交易的哈希值来获取这笔交易收据信息。
该接口返回的数据在一定程度上和eth_TransactionByHash是相同的,但该接口返回的数据更加详细,例如交易的日志Logs,这也是进行事件监听最主要的数据源。和eth_getTransactionByHash一样,处于pending状态的交易,返回的将会是空。返回的结构体是Receipt

The interface can capture the transaction receipt information based on the Hashi value of a transaction.
The interface returns the same data to a certain extent as Eth_TransactionByHash & #xff0c; but the interface returns more detailed data & #xff0c; for example, the transaction log Log Log Log Logs & #xff0c; this is also the most important source of data for event monitoring.

 
5.eth_getBalance

该接口获取的是某个ETH地址的ETH数值,即ETH余额。它不是获取ERC20 Token或者其他Token的余额。

The interface captures the ETH value of an ETH address xff0c; i.e. the ETH balance. It does not capture the balance of ERC20 Token or other Token.

6.eth_sendRawTransaction 和 eth_sendTransaction

具体请跳转,是所有交易的触发接口。其中eth_sendRawTransaction 可以完成的交易类型包含eth_sendTransaction.

, are trigger interfaces for all transactions.

7.eth_getTransactionCount

该接口可以根据一个ETH钱包地址获取当前钱包地址的交易序列号Nonce,该接口的第二参数是genesis、pending、latest,各个参数的分别对应的是下面的作用:

The interface can obtain the transaction serial number Nonce, of the current wallet address from an ETH wallet address; the second parameter of the interface is genesis,pending, latest, the respective parameters correspond to the role xff1a below;

  1. 取genesis时: 获取当前ETH地址第一次发起交易时的Nonce序列号
  2. 取pending时: 获取当前ETH地址提交了正处于pending状态等待被区块打包的交易订单所对应的Nonce序列号。如果当前查询的地址没有处于pending状态的交易,那么返回的是与latest一样的Nonce序列号。
  3. 取latest时: 获取当前ETH地址提交了且被区块打包成功的交易订单所对应的Nonce序列号加1的值。比如地址A最后一笔成功交易对应的Nonce为8,那么当调用接口传入参数为latest的时,获取的结果时9,即8+1.
  4. 在eth_getTransaction中,Nonce查询满足:pending>=latest>= genesis
8.eth_getCode

该接口根据ETH地址判断当前地址时合约地址还是非合约地址。如果不是,返回值是"0x",否则,返回的是智能合约当初创建时的十六进制码。

The interface determines whether the current address is a contractual or non-contractual address based on the ETH address. If not xff0c; returns value 34; 0x#34; otherwise xff0c; returns the hexadecimal number from the time the smart contract was created.

9.eth_estimateGas

该接口用来估算一笔交易要消耗多少GasLimit,该所估算出来的值没有涉及GasPrice。
入参中的data是被估算的数据量,估算的结果数值和数据量成正比。
这个接口在钱包发起交易的时让用户选择燃料费为多少的功能上会用到,提现在燃料费进度条中的最大值上。最大值一般就是这个接口返回的数值。

The interface is used to estimate how much GasLimit, is consumed by a transaction; the estimated value does not relate to GasPrice.
The included data data is the estimated amount of xff0c; the estimated results are proportional to the amount of data.
The interface allows the user to select the functionality of the fuel fee for the transaction at the time the wallet is initiated to xff0c; and refers to the maximum value in the current fuel cost progress. The maximum value is generally the value returned from this interface.

10.eth_call

这是ETH用来访问智能合约的万能RPC接口,也就是说,任何智能合约上的公有函数都能使用这个接口访问。

This is the `strong' almighty RPC interface used by ETH to access smart contracts & #xff0c; that is, xff0c; any public function on smart contracts can be accessed using this interface.

eth_getBalance是用来查询ETH余额的,但是ERC20 Token 余额,就需要通过eth_call来进行查询。这个接口的入参和 eth_sendRawTransaction/eth_sendTransaction入参是一样的。
eth_call接口是一个只读接口,不会改变区块链上的数据,可以访问ETH智能合约中的所有函数。

Eth_getBalance is the xff0c used to search for ETH balances; but the ERC20 Token balancexff0c; the search needs to be done through Eth_call. The entry into this interface is the same as the entry into Eth_sendRawTransation/eth_sendTransation.
eth_Call interface is a read-only interface xff0c; data on block chains are not changed xff0c; access to all functions in the ETH smart contract is available.

eth_call只读特性从源码上层面的理解
EVM在执行合约代码时,
先,使用区块号blockNumber找出对应的区块信息,
再,系统地根据这个区块的数据实例化一个名为status的变量,由status来实例化对应的EVM实例,
然后,根据区块提供的信息来实例化合约代码的变量值,即智能合约的函数在被执行前它的变量值是由当前区块高度决定的。
也就是说,eth_call在调用transfer函数时会直接在代码的内存层面进行值的修改,并没有广播出去和修改到数据层面。

eth_call read-only understanding of the properties from the source level
EVM xff0c; br/> xff0c; use block number Block number xff0c;
to find matching block information xff0c; b/> xff0c; systematize a variable named xff0c; xff0c; EVM example xus; r/> xff0c; exemplify the variable value of the contract code based on information provided by blocks xff0c; i.e., the variable value of the intelligent contract was determined at the highest level of the current block before it was implemented.
That is xff0c; Eth_call directly revises the value of the code xfer function; no xffffff0c to the data.

目前获取节点链接的的方案有两种

There are currently two options for obtaining node links.

  1. 自行购买服务器,然后启动ETH节点服务程序,例如Geth,再获取节点程序提供的接口链接。
  2. 使用第三方服务平台提供的节点链接

对于第一种方法,操作流程是先下载对应的ETH节点版本源码,然后根据文档的编译方法进行自编译,生成可执行程序,再部署到服务器。需要注意的是,ETH节点的源码不仅仅有版本号不同的版本,还有不同计算机语言的版本,官方的Geth是Golang语言开发的版本。

For the first method & #xff0c; the operating process is to download the corresponding ETH node source & #xff0c; then compose & #xff0c according to the compilation method of the document; generate the executable & #xff0c; then deploy to the server. Note that , the ETH node source code is not only a different version xff0c; there is also a different computer language version xff0c; the official Geth is a version developed in the Golang language.

第一种方整体实施起来的优缺点:
(1) 可自定义性高

The advantages and disadvantages of implemented as a whole by
(1) are self-defined

  • 可以自行配置节点启动的配置文件
  • 可自行修改源码进行二次开发后再编译
  • 可自行设置服务网关、节点集群等相关的运行方式
  • 可参与公链minter,赚取ETH的收入

(2) 技术要求难度相对来说比较高

(2) Relatively difficult technical requirements

  • 要求使用者必须掌握和了解配置文件中各项属性的含义及其影响
  • 要求使用者必须懂一些服务端运维的知识
  • 要求使用者懂得对应节点编写语言的编译命令,甚至使用过该门语言

(3) 自运维成本高

(3) High self-sustainment costs

  • 要求监控节点服务的运行情况
  • 要求实现节点程序,因为某些问题被杀死后能够进行自动重启
  • 在集群情况下,要求保证各服务的稳定性

(4) 需要自付费服务器等产品的花销

(4) Cost of products such as self-paid servers required

第二种方案

Second Option

  • 适用于学习阶段 和 线上业务不需要高度自定义化的情况使用

第二种方案和第一种方案对比,优缺点相反。
第二种方案也是最方便和便宜的,因为只需要一个链接即可。

The second option compares with the first option xff0c; the opposite is true.
The second option is also the most convenient and cheap xff0c; because only one link is needed.

链接获取

可以根据 https://infura.io/ 来免费获取节点链接。
Infura是国外一个托管ETH节点的集群,还允许开发者免费申请属于自己的ETH节点链接(包括主网和测试网),功能比较齐全和方便。

Free node links can be obtained from .
Infura is a host cluster of ETH nodes xff0c from abroad; developers are also allowed to apply for their ETH node links (including main and test networks) xff0c; it is more fully functional and convenient.

Detail go to 153 and 159。

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • 支付領域投下震撼彈!美國數位銀行Chime疑與GuardPay 神盾支付合作!

    支付領域投下震撼彈!美國數位銀行Chime疑與GuardPay 神盾支付合作!
    2020年,新冠肺炎(COVID-19)疫情加速數位貨幣進展。例如:2019年4月,國際清算銀行(BIS)的調查顯示,在全球66家中央銀行中,沒有一家計畫發行跨境支付的數位貨幣。惟到了2020年10月,BIS支付委員會主席康利夫(Jon Cunliffe)指出,肺炎疫情拉高民眾對無現金支付的需求,迫使各國加快數位貨幣的研發進程日本與韓國於2021年進入數位貨幣試驗階段。直到2019年12月,美國聯邦準備理事會(Fed)都尚無數位貨幣規劃,惟到了2020年2月,Fed已開始研擬...
  • 区块链:交易系统开发指南

    区块链:交易系统开发指南
    播报编辑《区块链:交易系统开发指南》使用通俗易懂的语言,从技术的角度详细介绍了区块链交易系统应有的功能架构及工作原理,让人们能够张开双臂轻松地拥抱区块链技术,享受区块链交易系统带来的惊喜与成就感。《区块链:交易系统开发指南》共分 7 章,第 1~2 章主要介绍区块链及数字货币的基本概念,以及各种公有链的 API 接口;第3~5 章主要介绍区块链交易系统的分类架构及功能; 6 章主要介绍区块链交易系统面临的问题及演进方向;第 7 章对全书做了总结。《区块链:交易系统开发指南》是...
  • 5.14加密货币价格:BTC突破6.2万美元以太坊和山寨币反映市场情绪

    5.14加密货币价格:BTC突破6.2万美元以太坊和山寨币反映市场情绪
    今天,随着比特币(BTC)的价格突破62 000美元的门槛,顶级加密货币的价格反弹了。 此外,以铁大幅上涨,维持在2 900美元的水平。 此外,其他顶尖山硬币,如索拉纳(SOL )、XRP、卡达诺(ADA )也大幅上涨。    今天密钥加密货币价格 1. 比特币价格    在5月14日星期二撰写本文时,比特币价格上升了2.57%,达到62 487.50美元。 另一方面,在过去24小时内,交易量从65.26 % 急剧上升至277亿美元。 与此同时,加密货币的市场价值为...
  • OKEx回应用户质疑:合约交易非期货 平台无机器人

    OKEx回应用户质疑:合约交易非期货 平台无机器人
       热点点 自选股份 数据中心 数据中心 研究和资料中心 资金流动 模拟交易 客户客户 具体来说,OKEx回答用户的问题:合同交易不是期货,平台不是机器人。 金融同步化,3月22日。    昨天下午,OKEx公司就维护先前用户线下的权利问题对同步财务公司作出了回应,指出OKEx公司提供的合同交易不是期货交易,在旗下的业务中没有正式的机器人。 同时,OKEX称,它不会以非法为由对任何投资损失索赔作出答复。 答复全文如下: 同步你的财务! 近日来,...
  • 0.00006694个比特币等于多少人民币/美金

    0.00006694个比特币等于多少人民币/美金
    0.00006694比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00006694比特币等于4.53424784美元/32.5436 16人民币。比特币(BTC)美元(USDT)人民币(CNY)0.000066944.53424784【比特币密码】32.82795436 16比特币对人民币的最新汇率为:490408.64 CNY(1比特币=490408.64人民币)(1美元=7.24人民币)(0.00006694USDT=0.0004846456 CNY)汇率更新时...
标签列表