Blockin
  • Blockin Overview
  • How Does It Work?
  • Developer Docs
    • Core Concepts
    • Getting Started
      • 🖊️User Signatures
      • 🖥️Sign In with BitBadges
      • 🆔Verification
      • 📤ChainDrivers
        • Setting Chain Drivers
        • Chain Driver Interface
        • Implementing a New Chain Driver
        • List of Implemented Chain Drivers
          • EthDriver
          • SolDriver
          • CosmosDriver
          • BtcDriver
          • AlgoDriver
    • Library Documentation
Powered by GitBook
On this page
  1. Developer Docs
  2. Getting Started
  3. ChainDrivers

Setting Chain Drivers

PreviousChainDriversNextChain Driver Interface

Last updated 1 year ago

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 to see some already implemented ChainDrivers, or see 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 ), or Blockin and its community provide some already implemented ChainDrivers (see ) 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;
    default:
      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

and

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

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

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.

See .

📤
Supported Chains
Adding a New Chain
Adding a New Chain
Supported Chains
https://github.com/Blockin-Labs/blockin-eth-driver/tree/main/src
https://github.com/BitBadges/bitbadges-indexer/tree/master/src/blockin