Rust Guide

Prerequisites

Overview

Fireblocks does not currently provide a native Rust SDK and so the recommended approach is to use the standard HTTP REST requests when calling the Fireblocks API.

However, an open source library was developed by the developer community that adds support for the Fireblocks wallet in the commonly used ethers-rs library for Ethereum (EVM) development in Rust.

Ethers-rs

Ethers-rs is a complete Ethereum & Celo library and wallet implementation in Rust.

Ethers-fireblocks is a project implementing ethers-rs compatibile Fireblocks Signer and Middleware.

Example

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 = 5; // Goerli
   let cfg = Config::new(
       &std::env::var("FIREBLOCKS_API_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://localhost: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(())
}

🚧

ethers-fireblocks is not built by Fireblocks

Please note that while it has Fireblocks in it's name - this is an open source library built by the developer community. Fireblocks does not maintain it and does not take any responsibility for current or future version of it.