Created
November 28, 2021 19:43
-
-
Save erwanor/8dca730b13714cbb9bc89830c9f38ac8 to your computer and use it in GitHub Desktop.
Signing Celo transaction using a Ledger and ethers-rs
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
use ethers::prelude::{HDPath, Signer, SignerMiddleware, TransactionRequest}; | |
use ethers::providers::*; | |
use ethers::signers::Ledger; | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let chain_id: u64 = 44787; | |
let rpc = "https://alfajores-forno.celo-testnet.org"; | |
println!("using rpc provider: {}", rpc); | |
println!("chain id: {}", chain_id); | |
let provider = Provider::<Http>::try_from(rpc).unwrap(); | |
let provider_chainid = provider.get_chainid().await?; | |
println!("provider chain id:{:?}", provider_chainid); | |
let ledger = Ledger::new(HDPath::LedgerLive(0), 1).await?.with_chain_id(chain_id); | |
let address = ledger.address(); | |
println!("address:{:?}", address); | |
println!("chain id: {}", ledger.chain_id()); | |
let client = SignerMiddleware::new(provider, ledger); | |
let tx = TransactionRequest::pay(address, 0); | |
println!("{:?}", tx); | |
let pending_tx = client.send_transaction(tx, None).await?; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment