Skip to content

buildervault-web3-provider 0.0.3

Install from the command line:
Learn more about npm packages
$ npm install @blockdaemon/buildervault-web3-provider@0.0.3
Install via package.json:
"@blockdaemon/buildervault-web3-provider": "0.0.3"

About this version

Blockdaemon BuilderVault Web3 Provider

Blockdaemon BuilderVault EIP-1193 Compatible Ethereum JavaScript Provider

Installation

npm config set @sepior:registry=https://gitlab.com/api/v4/projects/56306653/packages/npm/   # Builder Vault nodejsSDK public repository
npm config set @blockdaemon:registry=https://npm.pkg.github.com/        # Builder Vault Web3 provider nodejsSDK private repository
npm config set //npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT
npm install @blockdaemon/buildervault-web3-provider

Usage with ethers.js

npm install ethers@6
import * as ethers from "ethers"

const provider = new ethers.BrowserProvider(eip1193Provider);

Usage with web3.js

npm install web3
import Web3 from "web3";

const web3 = new Web3(eip1193Provider);

Usage with viem.sh

npm install viem
import { createWalletClient, custom } from 'viem'

const walletClient = createWalletClient({ 
  transport: custom({
    async request({ method, params }) {
      const response = await eip1193Provider.request({method, params})
      return response
    }
  })
})

API Documentation

BuildervaultProviderConfig

export type BuildervaultProviderConfig = {
  // ------------- Mandatory fields -------------
  /** 
   * Set the RPC API URL endpoint for JSON-RPC over HTTP access to the blockchain data
   */
  rpcUrl?: string,
  /** 
   * Set the numnber of the BuilderVault players
   */
  playerCount?: number
  /** 
   * Set the URL of each BuilderVault player endpoint
   */
  player0Url?: string,
  player1Url?: string,
  player2Url?: string,
  /**
   * Set the BuilderVault TSM API keys or use Client Certificate authentication
   */
  player0ApiKey?: string,
  player1ApiKey?: string,
  player2ApiKey?: string,
  /** 
   * Set the BuilderVault TSM mTLS Client Authentication Certficate key pair or use API Key authentication
   */
  player0ClientCert?: string,
  player0ClientKey?: string,
  player1ClientCert?: string,
  player1ClientKey?: string,
  player2ClientCert?: string,
  player2ClientKey?: string,
  /** 
   * BuilderVault Master Key ID. This ID represents all the private Master Key shares and must be generated outside if the web3 provider using the BuilderVault SDK
   */
  masterKeyId?: string,
  /** 
   * It is recommended to provide the account id explicitly.
   * This represents the <account> in the BIP44 chain path m/44/60/account/0/address_index
   */
  accountId?: number,
  /** 
   * By default, the first 5 addresses are derived from the master key
   * It is recommended to provide the address index explicitly.
   * This represents the <address_index> in the BIP44 chain path  m/44/60/account/0/address_index
   */
  addressIndex?: number,

  // ------------- Optional fields --------------
  /** 
   * Set the MPC publickey of each BuilderVault player. This is required for Dynamic communication between nodes such as through a broker and not static communication
   */
  player0MPCpublicKey?: string,
  player1MPCpublicKey?: string,
  player2MPCpublicKey?: string,
  /**
  /** 
   * Set the TLS publickey of each BuilderVault player endpoint. This is used for mTLS server certificate pinning.
   */
  player0mTLSpublicKey?: string,
  player1mTLSpublicKey?: string,
  player2mTLSpublicKey?: string,
  /**
   * Default: false
   * By setting to true, every request and response processed by the provider will be logged to the console
   * Same as setting env var `DEBUG=buildervault-web3-provider:req_res`
   */
  logRequestsAndResponses?: boolean,
}

Web3.js full client example

import { BuildervaultWeb3Provider } from "@blockdaemon/buildervault-web3-provider";
import Web3 from "web3";

const eip1193Provider = new BuildervaultWeb3Provider({
  rpcUrl: "https://svc.blockdaemon.com/native/v1/ethereum/holesky?apiKey=zpka_...",
  player0Url: "http://localhost:8500",
  player0ApiKey: "apikey...",
  player1Url: "http://localhost:8501",
  player1ApiKey: "apikey...",
  masterKeyId: "Ap3...",
  accountId: 0,   // account of BIP44 m/44/60/account/0/address_index
  addressIndex: 0, // address_index of BIP44 m/44/60/account/0/address_index
  logRequestsAndResponses: false,  // Verbose logging
})

async function main() {

  const web3 = new Web3(eip1193Provider);

  const chainId = await web3.eth.getChainId();
  console.log(`ChainID:`, chainId);

  const accounts = await web3.eth.getAccounts();
  console.log(`Wallet addresses:`, accounts);

  console.log(`Initial balance for address_index 0:`, await web3.eth.getBalance(accounts[0]));

  const feeData = await web3.eth.calculateFeeData();

  // Construct the transaction
  const transaction = {
    chainId: chainId,
    from: accounts[0],
    to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
    value: '1000000000000',
    maxFeePerGas: feeData.maxFeePerGas,
    maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
  }

  // Sign the transaction with BuilderVault, broadcast and wait for the receipt
  const receipt = await web3.eth.sendTransaction(transaction);

  // Log the transaction receipt
  console.log('Transaction receipt:', receipt);

  // Log final balances after the transaction has been mined
  console.log(`Final balance for address_index 0:`, await web3.eth.getBalance(accounts[0]));

}

main();

Details


Assets

  • buildervault-web3-provider-0.0.3.tgz

Download activity

  • Total downloads 1
  • Last 30 days 1
  • Last week 0
  • Today 0

Recent versions

View all