Transactions

How ethereum transaction work and how the ethereum blockchain make sure the transaction is authentic.

sendTransaction 函数一般有以下几个参数:

  1. from: [account]
  2. to: [account](optional)
  3. value:[integer] in wei
  4. gas:maximum amount of gas used
  5. gasPrice:amount of wei per gas
  6. data: ABI Byte string(optional)
  7. nonce: Integer of a nonce,in order to avoid replay attacks

例如:sendTransaction of web3.js

Signature

  • Transaction Signatures ensure authenticity of transactions
  • Signatures are generated from Private Keys

signTransaction of web3.js

三个参数:v,r,s 为签名. With these three parameter, we can authenticate the transaction isn't from malicious actor

16171092613915
16450841359407

步骤:

  1. 首先,我们通过 MetaMask 创建交易,from A to B,value=c
  2. MetaMask 存储发送方账户的私钥(私钥,32 bytes=64 hex characters)
  3. 通过 ECDSA 算法(Elliptic Curve Digital Signature Algorithm),得出公钥
  4. 通过取经过 Keccak 算法处理的公钥的后 20 字节,作为账户地址
  5. 通过私钥对交易进行签名,产生 v,r,s 三个重要参数
  6. 通过 v,r,s 利用 ECRECOVER 验证签名(通过 ecrecover 函数与签名可以得出签名者的公钥,进而得出签名者的地址,最终对比是否与声称的签名地址一致)

Public Keys and Addresses are generated from Private Keys. Private Keys have to be kept save under all circumstances

UTXO 讲解-比特币交易底层技术详解 - 知乎

中本聪创世铸币交易-Bitcoin CoinBase Tx