Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Harmony

Hierarchy

  • any
    • Harmony

Index

Constructors

constructor

  • new Harmony(url: string, config?: HarmonyConfig): Harmony
  • Create a harmony instance

    example
    // import or require Harmony class
    const { Harmony } = require('@harmony-js/core');
    
    // import or require settings
    const { ChainID, ChainType } = require('@harmony-js/utils');
    
    // Initialize the Harmony instance
    const hmy = new Harmony(
      // rpc url:
      // local: http://localhost:9500
      // testnet: https://api.s0.b.hmny.io/
      // mainnet: https://api.s0.t.hmny.io/
      'http://localhost:9500',
      {
        // chainType set to Harmony
        chainType: ChainType.Harmony,
        // chainType set to HmyLocal
        chainId: ChainID.HmyLocal,
      },
    );

    Parameters

    • url: string

      The end-points of the hmy blockchain

    • Default value config: HarmonyConfig = {chainId: utils.defaultConfig.Default.Chain_ID,chainType: utils.defaultConfig.Default.Chain_Type,}

      set up ChainID and ChainType, typically we can use the default values

    Returns Harmony

Methods

setChainId

  • setChainId(chainId: utils.ChainID): void
  • set the chainID

    hint
    Default = 0,
    EthMainnet = 1,
    Morden = 2,
    Ropsten = 3,
    Rinkeby = 4,
    RootstockMainnet = 30,
    RootstockTestnet = 31,
    Kovan = 42,
    EtcMainnet = 61,
    EtcTestnet = 62,
    Geth = 1337,
    Ganache = 0,
    HmyMainnet = 1,
    HmyTestnet = 2,
    HmyLocal = 2,
    HmyPangaea = 3
    example
    hmy.setChainId(2);

    Parameters

    • chainId: utils.ChainID

    Returns void

setChainType

  • setChainType(chainType: utils.ChainType): void
  • set the chainType

    example
    // set chainType to hmy
    hmy.setChainType('hmy');
    // set chainType to eth
    hmy.setChainType('eth');

    Parameters

    • chainType: utils.ChainType

      hmy or eth

    Returns void

setProvider

  • Will change the provider for its module.

    example
    const tmp = hmy.setProvider('http://localhost:9500');

    Parameters

    • provider: string | HttpProvider | WSProvider

      a valid provider, you can replace it with your own working node

    Returns void

setShardID

  • setShardID(shardID: number): void
  • Change the Shard ID

    example
    hmy.setShardID(2);

    Parameters

    • shardID: number

    Returns void

shardingStructures

  • shardingStructures(shardingStructures: ShardingItem[]): void
  • Set the sharding Structure

    example
    hmy.shardingStructures([
      {"current":true,"http":"http://127.0.0.1:9500",
       "shardID":0,"ws":"ws://127.0.0.1:9800"},
      {"current":false,"http":"http://127.0.0.1:9501",
       "shardID":1,"ws":"ws://127.0.0.1:9801"}
    ]);

    Parameters

    • shardingStructures: ShardingItem[]

      The array of information of sharding structures

    Returns void

Generated using TypeDoc