erc20

Rust ERC20 parser

This project intends to parse the Ethereum transactions from web3 into an abstraction that makes generic dealing with Ethereum or ERC20 transfers.

Code examples

Parsing a transfer

```rust let serialized_str = "a9059cbb0000000000000000000000006748f50f686bfbca6fe8ad62b22228b87f31ff2b00000000000000000000000000000000000000000000003635c9adc5dea00000";

let transaction = Transaction { hash: stringtoh256("43a5d6d13b6a9dca381e3f4b4677a4b9e5d9f80d1a5b6cfa2b1404fab733bcee".tostring()).unwrap(), nonce: Default::default(), blockhash: None, blocknumber: None, transactionindex: None, from: H160::random(), to: Some(H160::random()), value: Default::default(), gasprice: Default::default(), gas: Default::default(), input: Bytes(hex::decode(serializedstr).unwrap()), raw: None, };

let resp: Result = transaction.clone().try_into(); ```

Identifying an ERC20 contract address

```rust let tusdaddress = H160::fromstr("0000000000085d4780B73119b644AE5ecd22b376").unwrap(); asserteq!("0x0000000000085d4780b73119b644ae5ecd22b376".tostring(), format!("{:?}", tusd_address));

let contractaddress: ContractAddress = tusdaddress.into(); asserteq!(ContractAddress::TUSD, contractaddress);

// let tusdfromcontract: H160 = contractaddress.into(); // asserteq!(tusdaddress, tusdfrom_contract); ```

References