#middleware #signer #api #ethers #address #docs #fireblocks

ethers-fireblocks

为 Fireblocks API 提供的 ethers-rs 中间件和签名者

2 个版本

0.1.1 2021 年 8 月 29 日
0.1.0 2021 年 8 月 29 日

#28 in #ethers

每月 23 次下载

MIT/Apache

37KB
796

ethers-fireblocks

ethers 提供兼容的签名者和中间件实现,用于 Fireblocks 保险库 API

文档

克隆仓库并运行 cd ethers-fireblocks/ && cargo doc --open

将 ethers-fireblocks 添加到您的仓库

[dependencies]

ethers-fireblocks = { git = "https://github.com/gakonst/ethers-fireblocks" }

要使用示例,您必须设置以下环境变量

export FIREBLOCKS_API_SECRET_PATH=<path to your fireblocks.key>
export FIREBLOCKS_API_KEY=<your fireblocks api key>
export FIREBLOCKS_SOURCE_VAULT_ACCOUNT=<the vault id being used for sending txs>

示例用法

use ethers_core::types::{Address, TransactionRequest};
use ethers_fireblocks::{Config, FireblocksMiddleware, FireblocksSigner};
use ethers_providers::{Middleware, Provider};
use std::convert::TryFrom;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
   let wallet_id = "1"; // Our wallet id
   let chain_id = 3; // Ropsten
   let cfg = Config::new(
       &std::env::var("FIREBLOCKS_SECRET_PATH").expect("fireblocks secret not set"),
       &std::env::var("FIREBLOCKS_API_KEY").expect("fireblocks api key not set"),
       wallet_id,
       chain_id,
   )?;

   // Create the signer (it can also be used with ethers_signers::Wallet)
   let mut signer = FireblocksSigner::new(cfg).await;

   // Instantiate an Ethers provider
   let provider = Provider::try_from("http://127.0.0.1:8545")?;
   // Wrap the provider with the fireblocks middleware
   let provider = FireblocksMiddleware::new(provider, signer);

   // Any state altering transactions issued will be signed using
   // Fireblocks. Wait for your push notification and approve on your phone...
   let address: Address = "cbe74e21b070a979b9d6426b11e876d4cb618daf".parse()?;
   let tx = TransactionRequest::new().to(address);
   let pending_tx = provider.send_transaction(tx, None).await?;
   // Everything else follows the normal ethers-rs APIs
   // e.g. we can get the receipt after 6 confs
   let receipt = pending_tx.confirmations(6).await?;

   Ok(())
}

依赖项

~21–37MB
~711K SLoC