Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Blockchain

Hierarchy

  • Blockchain

Index

Methods

call

  • call(__namedParameters: { blockNumber: string; payload: any; shardID: number }): Promise<any>
  • Executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.

    example
    hmy.blockchain.call({
      to: "0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19",
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { blockNumber: string; payload: any; shardID: number }
      • blockNumber: string

        by default it's latest

      • payload: any

        some data you want put into these fucntions

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

createObservedTransaction

  • createObservedTransaction(transaction: Transaction): any
  • send a transaction and check whether it exists

    example
    // add privateKey to wallet
    const privateKey = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    hmy.wallet.addByPrivateKey(privateKey);
    
    async function transfer() {
      const txn = hmy.transactions.newTx({
        //  token send to
        to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
        // amount to send
        value: '10000',
        // gas limit, you can use string
        gasLimit: '210000',
        // send token from shardID
        shardID: 0,
        // send token to toShardID
        toShardID: 0,
        // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
        gasPrice: new hmy.utils.Unit('100').asGwei().toWei(),
      });
    
      // sign the transaction use wallet;
      const signedTxn = await hmy.wallet.signTransaction(txn);
      const txnHash = await hmy.blockchain.createObservedTransaction(signedTxn);
      console.log(txnHash);
    }
    
    transfer();

    Parameters

    • transaction: Transaction

      Object - The transaction object to send:

    Returns any

    The callbalck will return the 32 bytes transaction hash

estimateGas

  • estimateGas(__namedParameters: { data: string; shardID: number; to: string }): Promise<any>
  • Executes a message call or transaction and returns the amount of the gas used.

    warning
    At present, this function hmy_estimateGas is not implement yet, will Coming soon!!!
    example
    hmy.blockchain.estimateGas({
      to: 'one1d0kw95t6kkljmkk9vu0zv25jraut8ngv5vrs5g',
      data: '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { data: string; shardID: number; to: string }
      • data: string

        the data will send to that address

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

      • to: string

        the address will send to

    Returns Promise<any>

    promise - the used gas for the simulated call/transaction.

gasPrice

  • gasPrice(shardID?: number): Promise<any>
  • Returns the current gas price oracle. The gas price is determined by the last few blocks median gas price.

    example
    hmy.blockchain.gasPrice().then((value) => {
      console.log(value);
    });

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    promise - Number string of the current gas price in wei.

getBalance

  • getBalance(__namedParameters: { address: string; blockNumber: string; shardID: number }): Promise<any>
  • Get the balance of an address at a given block.

    hint
    the third param `shardID` is binding with the endpoint
    shard 0: localhost:9500
    shard 1: localhost:9501
    example
    hmy.blockchain.getBalance({
      address: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7',
      blockNumber: 'latest'
    }).then(value => {
      console.log(value.result);
    });

    Parameters

    • __namedParameters: { address: string; blockNumber: string; shardID: number }
      • address: string

        the address to get the balance of.

      • blockNumber: string

        (option) If you pass this parameter it will not use the default block set with DefaultBlockParams.latest

      • shardID: number

        (option) If you pass this parameter it will not use the default block set with this.messenger.currentShard

    Returns Promise<any>

    The current balance for the given address in wei.

getBlockByHash

  • getBlockByHash(__namedParameters: { blockHash: string; returnObject: boolean; shardID: number }): Promise<any>
  • Returns a block matching the block Hash.

    example
    hmy.blockchain.getBlockByHash({
      blockHash: '0x9cd821b576efdff61280e8857ef218fb2cff8db0cf0fb27dfceef7237042b79e',
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { blockHash: string; returnObject: boolean; shardID: number }
      • blockHash: string

        the block hash

      • returnObject: boolean

        By default it is true, Features in development, IGNORE it!

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - The block object

getBlockByNumber

  • getBlockByNumber(__namedParameters: { blockNumber: string; returnObject: boolean; shardID: number }): Promise<any>
  • Returns a block matching the block Number.

    example
    hmy.blockchain.getBlockByNumber({
      blockNumber: '0x89',
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { blockNumber: string; returnObject: boolean; shardID: number }
      • blockNumber: string

        the block number

      • returnObject: boolean

        By default it is true, Features in development, IGNORE it!

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - The block object

getBlockNumber

  • getBlockNumber(shardID?: number): Promise<any>
  • Returns the current block number.

    hint
    the third param `shardID` is binding with the endpoint
    shard 0: localhost:9500
    shard 1: localhost:9501
    example
    hmy.blockchain.getBlockNumber().then((value) => {
      console.log(value.result);
    });

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - The number of the most recent block.

getBlockTransactionCountByHash

  • getBlockTransactionCountByHash(__namedParameters: { blockHash: string; shardID: number }): Promise<any>
  • Returns the number of transaction in a given block.

    example
    hmy.blockchain.getBlockTransactionCountByHash({
      blockHash: '0x4142514a238157e7fe57b9d54abedb33943507fa15b3799954c273a12705ced1'
    }).then((value) => {
      console.log(value):
    });

    Parameters

    • __namedParameters: { blockHash: string; shardID: number }
      • blockHash: string

        the block number Hash

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - The number of transactions in the given block.

getBlockTransactionCountByNumber

  • getBlockTransactionCountByNumber(__namedParameters: { blockNumber: string; shardID: number }): Promise<any>
  • Returns the number of transaction in a given block.

    example
    hmy.blockchain.getBlockTransactionCountByNumber({
      blockNumber: '0x2403C'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { blockNumber: string; shardID: number }
      • blockNumber: string

        the block number Hash

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - The number of transactions in the given block.

getBlocks

  • getBlocks(__namedParameters: { from: string; shardID: number; to: string; blockArgs: object }): Promise<any>
  • Returns blocks in range [from; to]

    example
    hmy.blockchain.getBlocks({
      from: '0x89',
      to: '0x89',
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { from: string; shardID: number; to: string; blockArgs: object }
      • from: string

        starting block number in 0x format

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

      • to: string

        ending block number in 0x format

      • blockArgs: object

        optional args struct in json format (should be used just with { })

        • fullTx: false
        • withSigners: false

    Returns Promise<any>

    Promise - An array of block objects

getCode

  • getCode(__namedParameters: { address: string; blockNumber: string; shardID: number }): Promise<any>
  • Get the code at a specific address.

    example
    hmy.blockchain.getCode({
      address: '0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19',
      blockNumber: 'latest'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { address: string; blockNumber: string; shardID: number }
      • address: string

        The address to get the code from (eg:smart contract)

      • blockNumber: string

        (OPTIONAL) If you pass this parameter it will not use the default block

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - The data at given address

getCxReceiptByHash

  • getCxReceiptByHash(__namedParameters: { shardID: number; txnHash: string }): Promise<any>
  • Get transaction recepit from cross shard transaction

    example
    // This transaction sends from shard 0 to shard 1
    hmy.blockchain.getCxReceiptByHash({
      txnHash: '0x7fae9252fbda68d718e610bc10cf2b5c6a9cafb42d4a6b9d6e392c77d587b9ea',
      shardID: 1,
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { shardID: number; txnHash: string }
      • shardID: number

        the shard id of receiver's address

      • txnHash: string

        The transaction hash

    Returns Promise<any>

    Promise - A transaction receipt object, or null when no receipt was found

getProtocolVersion

  • getProtocolVersion(shardID?: number): Promise<any>
  • Get the protocal version.

    example
    hmy.blockchain.getProtocolVersion().then((value) => {
      console.log(value.result);
    });

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - the current protocol version.

getShardingStructure

  • getShardingStructure(): Promise<any>
  • Get the sharding structure of current network

    example
    hmy.blockchain.getShardingStructure().then((value) => {
      console.log(value);
    });

    Returns Promise<any>

    Promise - The sharding structure of current network.

getStorageAt

  • getStorageAt(__namedParameters: { address: string; blockNumber: string; position: string; shardID: number }): Promise<any>
  • Get the storage at a specific position of an address

    example
    hmy.blockchain.getStorageAt({
      address: 'one1d0kw95t6kkljmkk9vu0zv25jraut8ngv5vrs5g',
      position: '0x0'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { address: string; blockNumber: string; position: string; shardID: number }
      • address: string

        The address to get the storage from

      • blockNumber: string

        by default it's latest.

      • position: string

        The index position of the storage

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

getTransactionByBlockHashAndIndex

  • getTransactionByBlockHashAndIndex(__namedParameters: { blockHash: string; index: string; shardID: number }): Promise<any>
  • Returns a transaction based on a block hash and the transactions index position.

    example
    hmy.blockchain.getTransactionByBlockHashAndIndex({
      blockHash: '0x4142514a238157e7fe57b9d54abedb33943507fa15b3799954c273a12705ced1',
      index: '0x0'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { blockHash: string; index: string; shardID: number }
      • blockHash: string

        the block number Hash

      • index: string

        The transactions index position. Hex Number

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - A transaction object

getTransactionByBlockNumberAndIndex

  • getTransactionByBlockNumberAndIndex(__namedParameters: { blockNumber: string; index: string; shardID: number }): Promise<any>
  • Returns a transaction based on a block number and the transactions index position.

    example
    hmy.blockchain.getTransactionByBlockNumberAndIndex({
      blockNumber: '0x2403C',
      index: '0x0'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { blockNumber: string; index: string; shardID: number }
      • blockNumber: string

        the block number

      • index: string

        The transactions index position. Hex Number

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - A transaction object

getTransactionByHash

  • getTransactionByHash(__namedParameters: { shardID: number; txnHash: string }): Promise<any>
  • Returns a transaction matching the given transaction hash.

    example
    hmy.blockchain.getTransactionByHash({
      txnHash: '0x146a0cf7e8da45b44194207c4e7785564527059483b765f9a04424554443b224'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { shardID: number; txnHash: string }
      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

      • txnHash: string

        The transaction hash

    Returns Promise<any>

    Promise - A transaction object

getTransactionCount

  • getTransactionCount(__namedParameters: { address: string; blockNumber: string; shardID: number }): Promise<any>
  • Get the numbers of transactions sent from this address.

    example
    hmy.blockchain.getTransactionCount({
      address: "one1d0kw95t6kkljmkk9vu0zv25jraut8ngv5vrs5g"
    }).then((value) => {
      console.log(value.result);
    });

    Parameters

    • __namedParameters: { address: string; blockNumber: string; shardID: number }
      • address: string

        The address to get the numbers of transactions from

      • blockNumber: string

        by default it's latest

      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - The number of transactions sent from the given address.

getTransactionReceipt

  • getTransactionReceipt(__namedParameters: { shardID: number; txnHash: string }): Promise<any>
  • Returns the receipt of a transaction by transaction hash.

    example
    hmy.blockchain.getTransactionReceipt({
      txnHash: '0x146a0cf7e8da45b44194207c4e7785564527059483b765f9a04424554443b224'
    }).then((value) => {
      console.log(value);
    });

    Parameters

    • __namedParameters: { shardID: number; txnHash: string }
      • shardID: number

        shardID is binding with the endpoint, IGNORE it!

      • txnHash: string

        The transaction hash

    Returns Promise<any>

    Promise - A transaction receipt object, or null when no receipt was found

logs

  • logs(options: any, shardID?: number): any
  • example
    const hmy = new Harmony(
      // rpc url
      'ws://api.s0.b.hmny.io/',
      {
        // chainType set to Harmony
        chainType: ChainType.Harmony,
        // chainType set to HmyLocal
        chainId: ChainID.HmyLocal,
      },
    );
    
    const tmp = hmy.blockchain.logs({
      from: '0x12'
    });
    console.log(tmp)

    Parameters

    • options: any
    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns any

net_peerCount

  • net_peerCount(shardID?: number): Promise<any>
  • Get the number of peers connected to.

    example
    hmy.blockchain.net_peerCount().then((value) => {
      console.log(value.result);
    });

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - number of peer count

net_version

  • net_version(shardID?: number): Promise<any>
  • Get the version of net.

    example
    hmy.blockchain.net_version().then((value) => {
      console.log(value.result);
    });

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns Promise<any>

    Promise - the current version.

newBlockHeaders

  • newBlockHeaders(shardID?: number): any
  • example
    const hmy = new Harmony(
      // rpc url
      'ws://api.s0.b.hmny.io/',
      {
        // chainType set to Harmony
        chainType: ChainType.Harmony,
        // chainType set to HmyLocal
        chainId: ChainID.HmyLocal,
      },
    );
    
    const tmp = hmy.blockchain.newBlockHeaders();
    console.log(tmp)

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns any

newPendingTransactions

  • newPendingTransactions(shardID?: number): any
  • Return new pending Transactions

    example
    const hmy = new Harmony(
      // rpc url
      'ws://api.s0.b.hmny.io/',
      {
        // chainType set to Harmony
        chainType: ChainType.Harmony,
        // chainType set to HmyLocal
        chainId: ChainID.HmyLocal,
      },
    );
    
    const tmp = hmy.blockchain.newPendingTransactions();
    console.log(tmp)

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns any

sendRawTransaction

  • sendRawTransaction(transaction: Transaction): Promise<any>
  • Sends a raw transaction to the network.

    example
    // add privateKey to wallet
    const privateKey = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    hmy.wallet.addByPrivateKey(privateKey);
    
    async function transfer() {
      const txn = hmy.transactions.newTx({
        //  token send to
        to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
        // amount to send
        value: '10000',
        // gas limit, you can use string
        gasLimit: '210000',
        // send token from shardID
        shardID: 0,
        // send token to toShardID
        toShardID: 0,
        // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
        gasPrice: new hmy.utils.Unit('100').asGwei().toWei(),
      });
    
      // sign the transaction use wallet;
      const signedTxn = await hmy.wallet.signTransaction(txn);
      recovered = signedTxn.recover(signedTxn.rawTransaction);
    
      const txnHash = await hmy.blockchain.sendRawTransaction(recovered);
      console.log(txnHash);
    }
    
    transfer();

    Parameters

    • transaction: Transaction

      Object - The transaction object to send:

    Returns Promise<any>

    The callbalck will return the 32 bytes transaction hash

sendTransaction

  • sendTransaction(transaction: Transaction): Promise<any>
  • Sends a signed transaction to the network.

    example
    // add privateKey to wallet
    const privateKey = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
    hmy.wallet.addByPrivateKey(privateKey);
    
    async function transfer() {
      const txn = hmy.transactions.newTx({
        //  token send to
        to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
        // amount to send
        value: '10000',
        // gas limit, you can use string
        gasLimit: '210000',
        // send token from shardID
        shardID: 0,
        // send token to toShardID
        toShardID: 0,
        // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
        gasPrice: new hmy.utils.Unit('100').asGwei().toWei(),
      });
    
      // sign the transaction use wallet;
      const signedTxn = await hmy.wallet.signTransaction(txn);
      const txnHash = await hmy.blockchain.sendTransaction(signedTxn);
      console.log(txnHash.result);
    }
    
    transfer();

    Parameters

    • transaction: Transaction

      Object - The transaction object to send:

    Returns Promise<any>

    The callbalck will return the 32 bytes transaction hash

syncing

  • syncing(shardID?: number): any
  • example
    const hmy = new Harmony(
      // rpc url
      'ws://api.s0.b.hmny.io/',
      {
        // chainType set to Harmony
        chainType: ChainType.Harmony,
        // chainType set to HmyLocal
        chainId: ChainID.HmyLocal,
      },
    );
    
    const tmp = hmy.blockchain.syncing();
    console.log(tmp)

    Parameters

    • Default value shardID: number = this.messenger.currentShard

      shardID is binding with the endpoint, IGNORE it!

    Returns any

Generated using TypeDoc