Skip to content

Instantly share code, notes, and snippets.

@erwanor
Created November 28, 2021 19:43
Show Gist options
  • Save erwanor/8dca730b13714cbb9bc89830c9f38ac8 to your computer and use it in GitHub Desktop.
Save erwanor/8dca730b13714cbb9bc89830c9f38ac8 to your computer and use it in GitHub Desktop.
Signing Celo transaction using a Ledger and ethers-rs
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