Skip to content

Commit

Permalink
v.0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mich-master committed Dec 9, 2021
1 parent 883933d commit 233a1e0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk


# Added by cargo
#
# already existing elements were commented out

/target
#Cargo.lock
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "ethers-tools"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
web3 = "0.17"
ethers-core = { version = "0.6" }
ethers-signers = { version = "0.6" }
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use ethers_core::abi::ethereum_types::Address as AddressEth;
use ethers_core::types::U256;
use ethers_core::utils;
use ethers_signers::{ Signer, LocalWallet };

fn ethers_to_web3_address(address_ethers: AddressEth) -> web3::types::Address {
web3::types::H160(address_ethers.0)
}

pub struct EthersUtils {
address: AddressEth,
}

impl EthersUtils {
pub fn new(private_key: &str) -> Self {
let wallet: LocalWallet = private_key.parse::<LocalWallet>().unwrap();
let address: AddressEth = wallet.address();
EthersUtils {
address: address,
}
}
pub fn get_contract_address(&self, nonce: web3::types::U256) -> web3::types::Address {
let nonce_ethers: U256 = U256(nonce.0);
let address_ethers: AddressEth = utils::get_contract_address(self.address,nonce_ethers);
ethers_to_web3_address(address_ethers)
}
}

0 comments on commit 233a1e0

Please sign in to comment.