This commit is contained in:
Georgios Konstantopoulos 2020-05-24 18:55:46 +03:00
parent f82f8db57f
commit 4b6fbf00a8
No known key found for this signature in database
GPG Key ID: FA607837CD26EDBC
5 changed files with 31 additions and 16 deletions

View File

@ -1,12 +1,10 @@
use ethers::providers::{Provider, ProviderTrait};
use ethers::types::{BlockNumber, UnsignedTransaction};
use ethers::wallet::MainnetWallet;
use ethers::{types::UnsignedTransaction, HttpProvider, MainnetWallet};
use std::convert::TryFrom;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), failure::Error> {
let provider = Provider::try_from("http://localhost:8545")?;
let provider = HttpProvider::try_from("http://localhost:8545")?;
let client = MainnetWallet::from_str(
"d8ebe1e50cfea1f9961908d9df28e64bb163fee9ee48320361b2eb0a54974269",
)?
@ -19,7 +17,7 @@ async fn main() -> Result<(), failure::Error> {
let tx = UnsignedTransaction {
to: Some("986eE0C8B91A58e490Ee59718Cca41056Cf55f24".parse().unwrap()),
gas: 21000.into(),
gas_price: 100000.into(),
gas_price: 100_000.into(),
value: 10000.into(),
input: vec![].into(),
nonce,

View File

@ -1,20 +1,18 @@
use ethers::providers::{Provider, ProviderTrait};
use ethers::types::{Address, BlockNumber, TransactionRequest};
use ethers::{
types::{BlockNumber, TransactionRequest},
HttpProvider,
};
use std::convert::TryFrom;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), failure::Error> {
let provider = Provider::try_from("http://localhost:8545")?;
let from = Address::from_str("4916064D2E9C1b2ccC466EEc3d30B2b08F1C130D")?;
let provider = HttpProvider::try_from("http://localhost:8545")?;
let from = "4916064D2E9C1b2ccC466EEc3d30B2b08F1C130D".parse()?;
let tx_hash = provider
.send_transaction(TransactionRequest {
from,
to: Some(Address::from_str(
"9A7e5d4bcA656182e66e33340d776D1542143006",
)?),
to: Some("9A7e5d4bcA656182e66e33340d776D1542143006".parse()?),
value: Some(1000u64.into()),
gas: None,
gas_price: None,

View File

@ -1,10 +1,25 @@
//! ethers-rs
//!
//! ethers-rs is a port of [ethers-js](github.com/ethers-io/ethers.js) in Rust.
//!
//! # Quickstart
//!
//! ## Sending Ether
//!
//! ## Checking the state of the blockchain
//!
//! ## Deploying and interacting with a smart contract
//!
//! ## Watching on-chain events
//!
//! More examples can be found in the [`examples` directory of the
//! repositry](https://github.com/gakonst/ethers-rs)
pub mod providers;
pub use providers::HttpProvider;
pub mod signers;
pub use signers::{AnyWallet, MainnetWallet};
/// Ethereum related datatypes
pub mod types;

View File

@ -69,11 +69,11 @@ impl Provider {
}
}
impl TryFrom<&str> for Provider {
impl TryFrom<&str> for super::Provider<Provider> {
type Error = ParseError;
fn try_from(src: &str) -> Result<Self, Self::Error> {
Ok(Provider::new(Url::parse(src)?))
Ok(super::Provider(Provider::new(Url::parse(src)?)))
}
}

View File

@ -30,6 +30,10 @@ pub mod instantiated {
use super::*;
use crate::signers::Wallet;
/// A Wallet instantiated with chain_id = 1 for Ethereum Mainnet.
pub type MainnetWallet = Wallet<Mainnet>;
/// A wallet which does not use EIP-155 and does not take the chain id into account
/// when creating transactions
pub type AnyWallet = Wallet<EIP155Disabled>;
}