Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kms] Add feature to sign ethereum transaction #276

Merged
merged 22 commits into from
Jun 16, 2024
Merged

Conversation

yoshidan
Copy link
Owner

Integration with https://github.com/gakonst/ethers-rs.

Added since there did not seem to be any plans to support Google Cloud KMS in gakonst/ethers-rs#1.

I would like to port it to ethers-rs if possible.

 use ethers::prelude::SignerMiddleware;
 use ethers::providers::{Http, Middleware, Provider};
 use ethers_core::types::{TransactionReceipt, TransactionRequest};
 use ethers_signers::Signer as EthSigner;
 use google_cloud_kms::client::Client;
 use google_cloud_kms::signer::ethereum::{Error, Signer};

 pub async fn send_bnb(client: Client, key_name: &str) {

     // BSC testnet
     let chain_id = 97;

     let signer = Signer::new(client, key_name, chain_id, None).await.unwrap();
     let provider = Provider::<Http>::try_from("https://bsc-testnet-rpc.publicnode.com").unwrap();
  
     let eth_client = SignerMiddleware::new_with_provider_chain(provider, signer).await.unwrap();

     let tx = TransactionRequest::new()
             .to(signer.address())
             .value(100_000_000_000_000_u128)
             .gas(1_500_000_u64)
             .gas_price(4_000_000_000_u64)
             .chain_id(chain_id);

     let res = eth_client.send_transaction(tx, None).await.unwrap();
     let receipt: TransactionReceipt = res.confirmations(3).await.unwrap().unwrap();
 }

@yoshidan yoshidan self-assigned this Jun 15, 2024
@yoshidan yoshidan added the safe to test safe to test label Jun 15, 2024
@yoshidan yoshidan removed their assignment Jun 16, 2024
@yoshidan yoshidan added safe to test safe to test and removed safe to test safe to test labels Jun 16, 2024
@yoshidan yoshidan merged commit eb15032 into main Jun 16, 2024
@yoshidan yoshidan deleted the feature/eth_sign branch June 16, 2024 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test safe to test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant