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');
Last updated