ethers-rs/README.md

52 lines
1.5 KiB
Markdown
Raw Normal View History

2020-05-24 18:56:10 +00:00
# ethers.rs
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
Complete Ethereum wallet implementation and utilities in Rust (with WASM and FFI support).
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
## Features
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
- [x] User friendly transaction APIs
- [x] Type-safe EIP-155 transactions
- [ ] Event Monitoring
- [ ] Deploy and interact with smart contracts
- [ ] Type safe smart contract bindings
- [ ] Hardware wallet support
- [ ] ...
2020-05-22 18:37:21 +00:00
## Acknowledgements
This library would not have been possibly without the great work of the creators of [`rust-web3`]() and [`ethcontract-rs`]()
A lot of the code was inspired and adapted from them, to a unified and opinionated interface.
That said, Rust-web3 is ~9k LoC (tests included) and ethcontract-rs is 11k lines,
so in total about 20k lines of code with tests. This library is xxx LoC.
2020-05-24 18:56:10 +00:00
## Examples
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
### Sending a transaction with an offline key
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
```rust
use ethers::{types::TransactionRequest, HttpProvider, MainnetWallet};
use std::convert::TryFrom;
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
// connect to the network
let provider = HttpProvider::try_from("http://localhost:8545")?;
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
// create a wallet and connect it to the provider
let client = "15c42bf2987d5a8a73804a8ea72fb4149f88adf73e98fc3f8a8ce9f24fcb7774"
.parse::<MainnetWallet>()?
.connect(&provider);
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
// craft the transaction using the builder pattern
let tx = TransactionRequest::new()
.send_to_str("986eE0C8B91A58e490Ee59718Cca41056Cf55f24")?
.value(10000);
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
// send it!
let tx = client.sign_and_send_transaction(tx, None).await?;
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
// get the mined tx
let tx = client.get_transaction(tx.hash).await?;
2020-05-22 18:37:21 +00:00
2020-05-24 18:56:10 +00:00
println!("{}", serde_json::to_string(&tx)?);
```