Ethereum Development

Overview

Popular blockchain choices for building Web3 capabilities are based typically on the Ethereum Virtual Machine (EVM), and therefore share the development tech stack.

Some examples of EVM blockchains:

  • Ethereum
  • BNB Chain (BSC)
  • Polygon
  • Avalanche
  • Arbitrum

Convenience libraries

Most commonly, developers interact with EVM-based blockchains using "convenience libraries" such as web3.js and ethers.js.

To streamline your JavaScript development experience, we created the Fireblocks Web3 Provider, to easily connect ethers.js and web3.js to your Fireblocks workspace.

web3.js integration

The Fireblocks Web3 Provider helps seamlessly integrate Fireblocks into your web3.js development stack. Use it to deploy contracts, sign messages, and send transactions.

Installation

npm install @fireblocks/fireblocks-web3-provider web3

Setup

import { FireblocksWeb3Provider, ChainId } from "@fireblocks/fireblocks-web3-provider";

const eip1193Provider = new FireblocksWeb3Provider({
    apiBaseUrl: ApiBaseUrl.Sandbox // If using a sandbox workspace
    privateKey: process.env.FIREBLOCKS_API_PRIVATE_KEY_PATH,
    apiKey: process.env.FIREBLOCKS_API_KEY,
    vaultAccountIds: process.env.FIREBLOCKS_VAULT_ACCOUNT_IDS,
    chainId: ChainId.GOERLI,
})

If you are not using a Sandbox environment, but rather a regular one, just comment the apiBaseUrl line.

Usage

import Web3 from "web3";

const web3 = new Web3(eip1193Provider);

Now you can use the web3 object exactly as you normally would!

ethers.js integration

The Fireblocks Web3 Provider helps seamlessly integrate Fireblocks into your ethers.js development stack.

You can use it to deploy contracts, sign messages, and send transactions.

Installation

npm install @fireblocks/fireblocks-web3-provider [email protected]

Setup

import { FireblocksWeb3Provider, ChainId } from "@fireblocks/fireblocks-web3-provider";

const eip1193Provider = new FireblocksWeb3Provider({
    apiBaseUrl: ApiBaseUrl.Sandbox // If using a sandbox workspace
    privateKey: process.env.FIREBLOCKS_API_PRIVATE_KEY_PATH,
    apiKey: process.env.FIREBLOCKS_API_KEY,
    vaultAccountIds: process.env.FIREBLOCKS_VAULT_ACCOUNT_IDS,
    chainId: ChainId.GOERLI,
})

If you are not using a Sandbox environment, but rather a regular one, just comment the apiBaseUrl line.

Usage

import * as ethers from "ethers"

const provider = new ethers.providers.Web3Provider(eip1193Provider);

Now you can use the provider object exactly as you normally would!

web3.py integration

Fireblocks JSON-RPC helps seamlessly integrate Fireblocks into your web3.py development stack.

You can use it to deploy contracts, sign messages, and send transactions.

Installation

npm install -g @fireblocks/fireblocks-json-rpc
pip install web3

Setup

Set the environment variables.

Create example.py:

import json
import os
from web3 import Web3

web3 = Web3(Web3.IPCProvider(os.environ['FIREBLOCKS_JSON_RPC_ADDRESS'], 60000))
web3.eth.defaultAccount = web3.eth.accounts[0]
CONTRACT_ADDRESS = Web3.toChecksumAddress("0x8A470A36a1BDE8B18949599a061892f6B2c4fFAb")
GREETER_ABI = json.loads('[{"inputs":[{"internalType":"string","name":"_greeting","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"greet","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_greeting","type":"string"}],"name":"setGreeting","outputs":[],"stateMutability":"nonpayable","type":"function"}]')
GREETING = "Hello web3! By " + web3.eth.defaultAccount + " at " + str(datetime.now())

if __name__ == '__main__':
    print('last block number: ', web3.eth.blockNumber)
    for account in web3.eth.accounts:
        print('account: ', account)
        print('account balance: ', web3.fromWei(web3.eth.getBalance(account), "ether"), ' ETH\n')

    print('Greeter contract: https://goerli.etherscan.io/address/' + CONTRACT_ADDRESS)
   
    contract = web3.eth.contract(address=CONTRACT_ADDRESS, abi=GREETER_ABI)

    print('Current greeting:', contract.functions.greet().call())
    
    print('Setting greeting to:', GREETING)
    tx_hash = contract.functions.setGreeting(GREETING).transact()
    print('Transaction signed and broadcasted: https://goerli.etherscan.io/tx/' + tx_hash.hex())
    print('Waiting for transaction to be mined...')
    web3.eth.wait_for_transaction_receipt(tx_hash)

    print('Current greeting:', contract.functions.greet().call())



Usage

fireblocks-json-rpc -- python example.py

You can now use the web3 object exactly as you normally would!

ethers-rs integration

A community developed project implemented an ethers-fireblocks integration for the popular etheres-rs convenience library. More details and an example of usage is in the Rust Guide.