-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
883933d
commit 233a1e0
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |