Blockchain Transactions
Contents
Transactions
How ethereum transaction work and how the ethereum blockchain make sure the transaction is authentic.
sendTransaction
函数一般有以下几个参数:
from: [account]
to: [account](optional)
value:[integer] in wei
- gas:maximum amount of gas used
- gasPrice:amount of wei per gas
- data: ABI Byte string(optional)
- nonce: Integer of a nonce,in order to avoid replay attacks
Signature
- Transaction Signatures ensure authenticity of transactions
- Signatures are generated from Private Keys
三个参数:v,r,s 为签名. With these three parameter, we can authenticate the transaction isn't from malicious actor
![16171092613915](https://blog-1259556217.cos.ap-chengdu.myqcloud.com/image/16171092613915.jpg)
![16450841359407](https://blog-1259556217.cos.ap-chengdu.myqcloud.com/image/16450841359407.jpg)
步骤:
- 首先,我们通过 MetaMask 创建交易,from A to B,value=c
- MetaMask 存储发送方账户的私钥(私钥,32 bytes=64 hex characters)
- 通过 ECDSA 算法(Elliptic Curve Digital Signature Algorithm),得出公钥
- 通过取经过 Keccak 算法处理的公钥的后 20 字节,作为账户地址
- 通过私钥对交易进行签名,产生 v,r,s 三个重要参数
- 通过 v,r,s 利用 ECRECOVER 验证签名(通过 ecrecover 函数与签名可以得出签名者的公钥,进而得出签名者的地址,最终对比是否与声称的签名地址一致)
Public Keys and Addresses are generated from Private Keys. Private Keys have to be kept save under all circumstances