Setting Chain Drivers

With custom implementations (not outsourced), you can implement and setup your own ChainDrivers. Mix and match drivers as you wish according to your application's requirements. See Supported Chains to see some already implemented ChainDrivers, or see Adding a New Chain for how to create your own!

1) For each chain you want to support in your application, you will need a ChainDriver implementation for that blockchain (see below). You can either implement the interface yourself (see Adding a New Chain), or Blockin and its community provide some already implemented ChainDrivers (see Supported Chains) that you import (or use as starting points).

2) Once you have your ChainDriver implementations that you want to use in your application, you will need to handle getting it where needed.

import EthDriver from './EthDriver';
import CosmosDriver from './CosmosDriver';
import SolDriver from './SolDriver';
import BtcDriver from './BtcDriver';

const ethDriver = new EthDriver('0x1', undefined);
const solDriver = new SolDriver('');
const cosmosDriver = new CosmosDriver('bitbadges_1-1');

export const getChainDriver = (chain: string) => {
  switch (chain) {
    case 'Cosmos':
      return cosmosDriver;
    case 'Ethereum':
      return ethDriver;
    case 'Solana':
      return solDriver;
      return ethDriver;

//getChainDriver(...).verifySignature(...); //Use one of the driver's functions
//verifyChallenge(chainDriver, .....)

Option 1 - Directly Import: For the Blockin built or preexisting drivers, if all you need is the standard out of the box functionality you can install pre-existing ChainDrivers via:

npm i blockin-eth-driver
npm i blockin-cosmos-driver
npm i blockin-algo-driver


import { setChainDriver, ... } from 'blockin';
import AlgoDriver from 'blockin-algo-driver';
import EthDriver from 'blockin-eth-driver';
const EthereumDriver = new EthDriver(...);
const AlgorandDriver = new AlgoDriver(...);

Option 2 - Copy/Paste (Recommended): However, we actually find it a lot more flexible to simply copy and paste the driver files such as and use them directly in your project that way instead of importing via a library. They are small (only ~200 lines of code), and this allows you to perform minor tweaks and customization as needed, as well as seeing how they work behind the scenes.

import EthDriver from './customImplementation/EthDriver';
const EthereumDriver = new EthDriver(...);


Option 3 - Implement Your Own: Implement your own from scratch!

Last updated