1.以太坊的两种交易
以太坊中有两种交易,分别为普通交易和裸交易。普通交易由外部节点进行签名,然后发送到网络中进行确认;裸交易由外部应用进行签名,节点不再额外处理,而只是负责发送到网络中进行确认(未经节点加工的原始交易数据)。交易作为一种激励,使得账户的状态不断发生改变(账户余额),即产生了一种基于余额激励的以太坊状态机。
There are two types of transactions xff0c; ordinary transactions and naked transactions . Ordinary transactions are signed by external nodes xff0c; then sent to network for confirmation xff1b; nud trading is signed by external applications xff0c; nodes are no longer extra processing xff0c; rather, they are sent to the network for confirmation (original transaction data unprocessed).
2. Web3j获取账户余额
以太坊定义了eth_getBalance接口用来获取账户余额,在web3j中对应的封装方法为ethGetBalance(),响应对象为EthGetBalance:
The Eth_getBallance interface was defined to capture account balances & #xff0c; the corresponding encapsulation method in web3j was ethGetBallance() & #xff0c; the responding object was EthGetBallance:
执行结果:(单位为wei,相当于100个以太币)
Results of implementation xff1a; inwei, equivalent to 100 NT)
3.货币单位的表示与转换
Web3j中Unit的枚举类型定义以太坊货币的单位:
The list type of Unit in Web3j is defined as the unit of #xff1a in the Taiwan currency;
- Convert.Unit.WEI
- Convert.Unit.KWEI
- Convert.Unit.MWEI
- Convert.Unit.GWEI
- Convert.Unit.SZABO
- Convert.Unit.FINNEY
- Convert.Unit.ETHER
- Convert.Unit.KETHER
- Convert.Unit.METHER
- Convert.Unit.GETHER
进制转换实现:
结果:
Results xff1a;
4.两种交易
以太坊约定了两种交易不同的提交接口:普通交易使eth_sendTransaction 调用提交,而裸交易则应当使用eth_sendRawTransaction调用提交。事实上,在公共节点中,通常会拒绝普通交易的提交,而要求外部应用必须进行离线签名。
下节中再详细讲述两种交易的具体实现过程~~
In fact, xff0c; in public nodes xff0c; usually the submission of ordinary transactions is denied xff0c; the external application has to be signed off.
details about the specific process of realization of the two transactions ~ in the next section .
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论