Etherspot
These are our V1 docs and will be deprecated soon. Please visit https://etherspot.fyi/introduction to use our new version of the SDK.
  • Welcome to Etherspot
    • Chains, Bridges & DEXes
    • Social Logins
    • Web3 Logins
  • Transaction Kit
    • Introduction
    • Code Sandboxes
    • Quick Start
    • React Hooks
      • useEtherspotAssets()
      • useEtherspotNfts()
      • useEtherspotHistory()
        • getAccountTransactions()
        • getAccountTransaction()
      • useEtherspotTransactions()
        • estimate()
        • send()
      • useEtherspotAddresses()
      • useEtherspotBalances()
    • React Components
      • <EtherspotTransactionKit />
      • <EtherspotBatches />
      • <EtherspotBatch />
      • <EtherspotTransaction />
      • <EtherspotContractTransaction />
      • <EtherspotApprovalTransaction />
      • <EtherspotTokenTransferTransaction />
  • BUIDLER React Component
    • Introduction
    • Installation
    • Integrate React Component
    • Shared Sessions
    • Wallet Connectors
    • Blocks
      • Send
      • Batching Transaction
      • Multicall Transaction
      • Swaps
      • Bridges
      • Custom Contract Interactions
      • Styling
    • Build Your Own Block
      • Cross-chain KLIMA DAO Staking
  • Etherspot SDK Guides
    • Requirements
    • Install Etherspot SDK
    • Bootstrap Etherspot SDK
      • Instantiate Etherspot SDK
    • Events
    • Etherspot Block Explorer
    • Etherspot Playground
    • Social Login using Etherspot SDK
    • Sponsored Transactions
  • Use Cases & Guides
    • Crosschain Streaming
    • Token Swaps
    • Transactions
      • Historical
      • Sending
    • Multi-chain Bridges
      • ERC20 Bridge
      • DAI - xDai Bridge
      • xDai - DAI Bridge
      • Native Token Bridge
    • Custom Contract Interaction
    • Multi-chain Assets
    • Multi-chain Gas Prices
    • Peer-to-Peer Payments
  • Reference
    • Etherspot SDK API Docs
    • Etherspot SDK on Github
    • Etherspot on NPM
    • Etherspot Playground
    • Etherspot Block Explorer
    • Etherspot Architecture
    • EIP-1271
    • Etherspot/Pillar Audit
  • Brand Assets
    • Etherspot Brand Assets
  • Security
    • Security
  • Get in touch
    • ⚒️Discord
    • Twitter
    • Telegram
Powered by GitBook
On this page
  • Instantiating on all available chains
  • Instantiating on a single chain

Was this helpful?

  1. Etherspot SDK Guides
  2. Bootstrap Etherspot SDK

Instantiate Etherspot SDK

Instantiating on all available chains

Use the same private key or authentication method when instantiating an instance of the Etherspot SDK to generate the same Ethereum address across all chains!

Here we show you a basic example of how you could go about instantiating all the networks we support and make them available via a class.

import {
  Sdk as EtherspotSdk,
  NetworkNames,
} from 'etherspot';

class EtherspotService {
  instances: { [network: string]: EtherspotSdk } = {};
  
  init(privateKey: string): void {
    /**
    * You can use this space to do anything else
    * you're application may require to run.
    */ 
    
    // Mainnet
    this.instances[NetworkNames.Mainnet] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Mainnet });
      
    // Gnosis Chain (xDai)
    this.instances[NetworkNames.Xdai] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Xdai });
    
    // Binance Smart Chain
    this.instances[NetworkNames.Bsc] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Bsc });
        
    // Polygon, formerly known as Matic
    this.instances[NetworkNames.Matic] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Matic });
      
    // Fantom
    this.instances[NetworkNames.Fantom] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Fantom });
    
    // Aurora
    this.instances[NetworkNames.Aurora] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Aurora });
    
    // Avalanche
    this.instances[NetworkNames.Avalanche] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Avalanche });   
    
    // Arbitrum
    this.instances[NetworkNames.Arbitrum] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Arbitrum });  
    
    // Moonbeam
    this.instances[NetworkNames.Moonbeam] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Moonbeam }); 
      
    // Celo
    this.instances[NetworkNames.Celo] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Celo });
      
    // Fuse
    this.instances[NetworkNames.Fuse] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Fuse });
    
    // ArbitrumNova
    this.instances[NetworkNames.ArbitrumNova] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.ArbitrumNova });
      
    // Optimism
    this.instances[NetworkNames.Optimism] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Optimism });
      
    // Neon
    this.instances[NetworkNames.Neon] =
      new EtherspotSdk(privateKey, { networkName: NetworkNames.Neon });      
  }
}

Instantiating on a single chain

Below is some examples of how you would instantiate an instance on the Etherspot SDK on a single chain.

import { Sdk, NetworkNames, randomPrivateKey } from 'etherspot';

const privateKey = randomPrivateKey();
let sdk: Sdk

/**
* Replace `privateKey` with your own private key
* or Etherspot Authentication method.
*/
sdk = new Sdk({
  privateKey,
}, {
  networkName: 'mainnet' as NetworkNames,
});

console.info('SDK created');
import { Sdk, NetworkNames, randomPrivateKey } from 'etherspot';

const privateKey = randomPrivateKey();
let sdk: Sdk

/**
* Replace `privateKey` with your own private key
* or Etherspot Authentication method.
*/
sdk = new Sdk({
  privateKey,
}, {
  networkName: 'matic' as NetworkNames,
});

console.info('SDK created');
import { Sdk, NetworkNames, randomPrivateKey } from 'etherspot';

const privateKey = randomPrivateKey();
let sdk: Sdk

/**
* Replace `privateKey` with your own private key
* or Etherspot Authentication method.
*/
sdk = new Sdk({
  privateKey,
}, {
  networkName: 'xdai' as NetworkNames,
});

console.info('SDK created');
import { Sdk, NetworkNames, randomPrivateKey } from 'etherspot';

const privateKey = randomPrivateKey();
let sdk: Sdk

/**
* Replace `privateKey` with your own private key
* or Etherspot Authentication method.
*/
sdk = new Sdk({
  privateKey,
}, {
  networkName: 'bsc' as NetworkNames,
});

console.info('SDK created');
import { Sdk, NetworkNames, randomPrivateKey } from 'etherspot';

const privateKey = randomPrivateKey();
let sdk: Sdk

/**
* Replace `privateKey` with your own private key
* or Etherspot Authentication method.
*/
sdk = new Sdk({
  privateKey,
}, {
  networkName: 'fantom' as NetworkNames,
});

console.info('SDK created');
PreviousBootstrap Etherspot SDKNextEvents

Last updated 2 years ago

Was this helpful?