@ -1,20 +1,20 @@
/ * *
# @harmony - js / core
# @woop - js / core
This package provides a collection of apis to interact with Harmony blockchain .
This package provides a collection of apis to interact with Woop blockchain .
# # Installation
` ` `
npm install @harmony - js / core
npm install @woop - js / core
` ` `
# # Usage
Create a Harmony instance connecting to testnet
Create a Woop instance connecting to testnet
` ` ` javascript
* const { Harmony } = require ( '@harmony -js/core' ) ;
* const { Woop } = require ( '@woop -js/core' ) ;
* const {
* ChainID ,
* ChainType ,
@ -23,20 +23,20 @@ Create a Harmony instance connecting to testnet
* fromWei ,
* Units ,
* Unit ,
* } = require ( '@harmony -js/utils' ) ;
* } = require ( '@woop -js/utils' ) ;
* const hmy = new Harmony (
* const wiki = new Woop (
* 'https://api.s0.b.hmny.io/' ,
* {
* chainType : ChainType.Harmony ,
* chainId : ChainID.Hmy Testnet ,
* chainType : ChainType.Woop ,
* chainId : ChainID.Wiki Testnet ,
* } ,
* ) ;
` ` `
Getting balance of account ` one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7 `
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getBalance ( { address : 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7' } )
* . then ( ( response ) = > {
* console . log ( 'balance in ONEs: ' + fromWei ( hexToNumber ( response . result ) , Units . one ) ) ;
@ -45,14 +45,14 @@ Getting balance of account `one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7`
Getting the latest block number
` ` ` javascript
* hmy . blockchain . getBlockNumber ( ) . then ( ( response ) = > {
* wiki . blockchain . getBlockNumber ( ) . then ( ( response ) = > {
* console . log ( 'current block number: ' + hexToNumber ( response . result ) ) ;
* } ) ;
` ` `
Getting the block using block hash
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getBlockByHash ( {
* blockHash : '0x08c46ae7249362a7d1f602d44c5a81f33ebdab6a7dcb6068f99610b57911aafd' ,
* } )
@ -63,7 +63,7 @@ Getting the block using block hash
Getting the block using block number
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getBlockByNumber ( {
* blockNumber : numberToHex ( 422635 ) ,
* } )
@ -74,7 +74,7 @@ Getting the block using block number
Getting the transaction using hash
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getTransactionByHash ( {
* txnHash : '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831' ,
* } )
@ -85,7 +85,7 @@ Getting the transaction using hash
Getting the transaction receipt
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getTransactionReceipt ( {
* txnHash : '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831' ,
* } )
@ -96,7 +96,7 @@ Getting the transaction receipt
Getting the cross - shard transaction receipt
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getCxReceiptByHash ( {
* txnHash : '0xcd36a90ff5d5373285c2896ba7bbcd3f5324263c0cb8ecfb7cad2f5fc2fbdbda' ,
* shardID : 1 ,
@ -108,7 +108,7 @@ Getting the cross-shard transaction receipt
Getting the deployed smart contract code
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getCode ( {
* address : '0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19' ,
* blockNumber : 'latest' ,
@ -120,7 +120,7 @@ Getting the deployed smart contract code
Getting the transaction count of an account
` ` ` javascript
* hmy . blockchain
* wiki . blockchain
* . getTransactionCount ( {
* address : 'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy' ,
* } )
@ -131,7 +131,7 @@ Getting the transaction count of an account
Getting the shard structure and details
` ` ` javascript
* hmy . blockchain . getShardingStructure ( ) . then ( ( response ) = > {
* wiki . blockchain . getShardingStructure ( ) . then ( ( response ) = > {
* console . log ( response . result ) ;
* } ) ;
` ` `
@ -139,10 +139,10 @@ Getting the shard structure and details
Transferring funds using ` sendTransaction `
` ` ` javascript
// key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
* hmy . wallet . addByPrivateKey ( '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e' ) ;
* wiki . wallet . addByPrivateKey ( '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e' ) ;
* async function transfer() {
* const txn = hmy . transactions . newTx ( {
* const txn = wiki . transactions . newTx ( {
* to : 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2' ,
* value : new Unit ( 1 ) . asOne ( ) . toWei ( ) ,
* // gas limit, you can use string
@ -152,12 +152,12 @@ Transferring funds using `sendTransaction`
* // 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 ( '1' ) . asGwei ( ) . toWei ( ) ,
* gasPrice : new wiki . utils . Unit ( '1' ) . asGwei ( ) . toWei ( ) ,
* } ) ;
* // sign the transaction use wallet;
* const signedTxn = await hmy . wallet . signTransaction ( txn ) ;
* const txnHash = await hmy . blockchain . sendTransaction ( signedTxn ) ;
* const signedTxn = await wiki . wallet . signTransaction ( txn ) ;
* const txnHash = await wiki . blockchain . sendTransaction ( signedTxn ) ;
* console . log ( txnHash . result ) ;
* }
@ -165,7 +165,7 @@ Transferring funds using `sendTransaction`
` ` `
*
* @packageDocumentation
* @module harmony - core
* @module woop - core
* /
import {
@ -177,19 +177,19 @@ import {
NewHeaders ,
LogSub ,
Syncing ,
} from '@harmony -js/network' ;
} from '@woop -js/network' ;
import {
assertObject ,
AssertType ,
// Harmony Core,
// Woop Core,
DefaultBlockParams ,
} from '@harmony -js/utils' ;
} from '@woop -js/utils' ;
import { getAddress } from '@harmony -js/crypto' ;
import { getAddress } from '@woop -js/crypto' ;
import { Transaction } from '@harmony -js/transaction' ;
import { StakingTransaction } from '@harmony -js/staking' ;
import { Transaction } from '@woop -js/transaction' ;
import { StakingTransaction } from '@woop -js/staking' ;
class Blockchain {
/ * *
@ -241,7 +241,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getBalance ( {
* wiki . blockchain . getBalance ( {
* address : 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7' ,
* blockNumber : 'latest'
* } ) . then ( value = > {
@ -287,7 +287,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getBlockNumber ( ) . then ( ( value ) = > {
* wiki . blockchain . getBlockNumber ( ) . then ( ( value ) = > {
* console . log ( value . result ) ;
* } ) ;
* ` ` `
@ -312,7 +312,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getBlockByHash ( {
* wiki . blockchain . getBlockByHash ( {
* blockHash : '0x9cd821b576efdff61280e8857ef218fb2cff8db0cf0fb27dfceef7237042b79e' ,
* } ) . then ( ( value ) = > {
* console . log ( value ) ;
@ -352,7 +352,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getBlockByNumber ( {
* wiki . blockchain . getBlockByNumber ( {
* blockNumber : '0x89' ,
* } ) . then ( ( value ) = > {
* console . log ( value ) ;
@ -393,7 +393,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getBlocks ( {
* wiki . blockchain . getBlocks ( {
* from : '0x89' ,
* to : '0x89' ,
* } ) . then ( ( value ) = > {
@ -442,7 +442,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getBlockTransactionCountByHash ( {
* wiki . blockchain . getBlockTransactionCountByHash ( {
* blockHash : '0x4142514a238157e7fe57b9d54abedb33943507fa15b3799954c273a12705ced1'
* } ) . then ( ( value ) = > {
* console . log ( value ) :
@ -478,7 +478,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getBlockTransactionCountByNumber ( {
* wiki . blockchain . getBlockTransactionCountByNumber ( {
* blockNumber : '0x2403C'
* } ) . then ( ( value ) = > {
* console . log ( value ) ;
@ -515,7 +515,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getTransactionByBlockHashAndIndex ( {
* wiki . blockchain . getTransactionByBlockHashAndIndex ( {
* blockHash : '0x4142514a238157e7fe57b9d54abedb33943507fa15b3799954c273a12705ced1' ,
* index : '0x0'
* } ) . then ( ( value ) = > {
@ -556,7 +556,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getTransactionByBlockNumberAndIndex ( {
* wiki . blockchain . getTransactionByBlockNumberAndIndex ( {
* blockNumber : '0x2403C' ,
* index : '0x0'
* } ) . then ( ( value ) = > {
@ -596,7 +596,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getTransactionByHash ( {
* wiki . blockchain . getTransactionByHash ( {
* txnHash : '0x146a0cf7e8da45b44194207c4e7785564527059483b765f9a04424554443b224'
* } ) . then ( ( value ) = > {
* console . log ( value ) ;
@ -632,7 +632,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getTransactionReceipt ( {
* wiki . blockchain . getTransactionReceipt ( {
* txnHash : '0x146a0cf7e8da45b44194207c4e7785564527059483b765f9a04424554443b224'
* } ) . then ( ( value ) = > {
* console . log ( value ) ;
@ -669,7 +669,7 @@ class Blockchain {
* @example
* ` ` ` javascript
* // This transaction sends from shard 0 to shard 1
* hmy . blockchain . getCxReceiptByHash ( {
* wiki . blockchain . getCxReceiptByHash ( {
* txnHash : '0x7fae9252fbda68d718e610bc10cf2b5c6a9cafb42d4a6b9d6e392c77d587b9ea' ,
* shardID : 1 ,
* } ) . then ( ( value ) = > {
@ -701,7 +701,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getCode ( {
* wiki . blockchain . getCode ( {
* address : '0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19' ,
* blockNumber : 'latest'
* } ) . then ( ( value ) = > {
@ -740,7 +740,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . net_peerCount ( ) . then ( ( value ) = > {
* wiki . blockchain . net_peerCount ( ) . then ( ( value ) = > {
* console . log ( value . result ) ;
* } ) ;
* ` ` `
@ -759,7 +759,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . net_version ( ) . then ( ( value ) = > {
* wiki . blockchain . net_version ( ) . then ( ( value ) = > {
* console . log ( value . result ) ;
* } ) ;
* ` ` `
@ -778,7 +778,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getProtocolVersion ( ) . then ( ( value ) = > {
* wiki . blockchain . getProtocolVersion ( ) . then ( ( value ) = > {
* console . log ( value . result ) ;
* } ) ;
* ` ` `
@ -803,7 +803,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getStorageAt ( {
* wiki . blockchain . getStorageAt ( {
* address : 'one1d0kw95t6kkljmkk9vu0zv25jraut8ngv5vrs5g' ,
* position : '0x0'
* } ) . then ( ( value ) = > {
@ -847,7 +847,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getTransactionCount ( {
* wiki . blockchain . getTransactionCount ( {
* address : "one1d0kw95t6kkljmkk9vu0zv25jraut8ngv5vrs5g"
* } ) . then ( ( value ) = > {
* console . log ( value . result ) ;
@ -884,7 +884,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . getShardingStructure ( ) . then ( ( value ) = > {
* wiki . blockchain . getShardingStructure ( ) . then ( ( value ) = > {
* console . log ( value ) ;
* } ) ;
* ` ` `
@ -908,10 +908,10 @@ class Blockchain {
* ` ` ` javascript
* // add privateKey to wallet
* const privateKey = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e' ;
* hmy . wallet . addByPrivateKey ( privateKey ) ;
* wiki . wallet . addByPrivateKey ( privateKey ) ;
*
* async function transfer() {
* const txn = hmy . transactions . newTx ( {
* const txn = wiki . transactions . newTx ( {
* // token send to
* to : 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2' ,
* // amount to send
@ -923,12 +923,12 @@ class Blockchain {
* // 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 ( ) ,
* gasPrice : new wiki . utils . Unit ( '100' ) . asGwei ( ) . toWei ( ) ,
* } ) ;
*
* // sign the transaction use wallet;
* const signedTxn = await hmy . wallet . signTransaction ( txn ) ;
* const txnHash = await hmy . blockchain . sendTransaction ( signedTxn ) ;
* const signedTxn = await wiki . wallet . signTransaction ( txn ) ;
* const txnHash = await wiki . blockchain . sendTransaction ( signedTxn ) ;
* console . log ( txnHash . result ) ;
* }
*
@ -960,10 +960,10 @@ class Blockchain {
* ` ` ` javascript
* // add privateKey to wallet
* const privateKey = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e' ;
* hmy . wallet . addByPrivateKey ( privateKey ) ;
* wiki . wallet . addByPrivateKey ( privateKey ) ;
*
* async function transfer() {
* const txn = hmy . transactions . newTx ( {
* const txn = wiki . transactions . newTx ( {
* // token send to
* to : 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2' ,
* // amount to send
@ -975,14 +975,14 @@ class Blockchain {
* // 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 ( ) ,
* gasPrice : new wiki . utils . Unit ( '100' ) . asGwei ( ) . toWei ( ) ,
* } ) ;
*
* // sign the transaction use wallet;
* const signedTxn = await hmy . wallet . signTransaction ( txn ) ;
* const signedTxn = await wiki . wallet . signTransaction ( txn ) ;
* recovered = signedTxn . recover ( signedTxn . rawTransaction ) ;
*
* const txnHash = await hmy . blockchain . sendRawTransaction ( recovered ) ;
* const txnHash = await wiki . blockchain . sendRawTransaction ( recovered ) ;
* console . log ( txnHash ) ;
* }
*
@ -1009,10 +1009,10 @@ class Blockchain {
* ` ` ` javascript
* // add privateKey to wallet
* const privateKey = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e' ;
* hmy . wallet . addByPrivateKey ( privateKey ) ;
* wiki . wallet . addByPrivateKey ( privateKey ) ;
*
* async function transfer() {
* const txn = hmy . transactions . newTx ( {
* const txn = wiki . transactions . newTx ( {
* // token send to
* to : 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2' ,
* // amount to send
@ -1024,12 +1024,12 @@ class Blockchain {
* // 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 ( ) ,
* gasPrice : new wiki . utils . Unit ( '100' ) . asGwei ( ) . toWei ( ) ,
* } ) ;
*
* // sign the transaction use wallet;
* const signedTxn = await hmy . wallet . signTransaction ( txn ) ;
* const txnHash = await hmy . blockchain . createObservedTransaction ( signedTxn ) ;
* const signedTxn = await wiki . wallet . signTransaction ( txn ) ;
* const txnHash = await wiki . blockchain . createObservedTransaction ( signedTxn ) ;
* console . log ( txnHash ) ;
* }
*
@ -1108,12 +1108,12 @@ class Blockchain {
*
* @warning
* ` ` `
* At present , this function hmy _estimateGas is not implement yet , will Coming soon ! ! !
* At present , this function wiki _estimateGas is not implement yet , will Coming soon ! ! !
* ` ` `
*
* @example
* ` ` ` javascript
* hmy . blockchain . estimateGas ( {
* wiki . blockchain . estimateGas ( {
* to : 'one1d0kw95t6kkljmkk9vu0zv25jraut8ngv5vrs5g' ,
* data : '0xc6888fa10000000000000000000000000000000000000000000000000000000000000003'
* } ) . then ( ( value ) = > {
@ -1152,7 +1152,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . gasPrice ( ) . then ( ( value ) = > {
* wiki . blockchain . gasPrice ( ) . then ( ( value ) = > {
* console . log ( value ) ;
* } ) ;
* ` ` `
@ -1177,7 +1177,7 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* hmy . blockchain . call ( {
* wiki . blockchain . call ( {
* to : "0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19" ,
* } ) . then ( ( value ) = > {
* console . log ( value ) ;
@ -1209,18 +1209,18 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* const hmy = new Harmony (
* const wiki = new Woop (
* // rpc url
* 'ws://api.s0.b.hmny.io/' ,
* {
* // chainType set to Harmony
* chainType : ChainType.Harmony ,
* // chainType set to Hmy Local
* chainId : ChainID.Hmy Local ,
* // chainType set to Woop
* chainType : ChainType.Woop ,
* // chainType set to Wiki Local
* chainId : ChainID.Wiki Local ,
* } ,
* ) ;
*
* const tmp = hmy . blockchain . newPendingTransactions ( ) ;
* const tmp = wiki . blockchain . newPendingTransactions ( ) ;
* console . log ( tmp )
* ` ` `
* /
@ -1238,18 +1238,18 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* const hmy = new Harmony (
* const wiki = new Woop (
* // rpc url
* 'ws://api.s0.b.hmny.io/' ,
* {
* // chainType set to Harmony
* chainType : ChainType.Harmony ,
* // chainType set to Hmy Local
* chainId : ChainID.Hmy Local ,
* // chainType set to Woop
* chainType : ChainType.Woop ,
* // chainType set to Wiki Local
* chainId : ChainID.Wiki Local ,
* } ,
* ) ;
*
* const tmp = hmy . blockchain . newBlockHeaders ( ) ;
* const tmp = wiki . blockchain . newBlockHeaders ( ) ;
* console . log ( tmp )
* ` ` `
* /
@ -1267,18 +1267,18 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* const hmy = new Harmony (
* const wiki = new Woop (
* // rpc url
* 'ws://api.s0.b.hmny.io/' ,
* {
* // chainType set to Harmony
* chainType : ChainType.Harmony ,
* // chainType set to Hmy Local
* chainId : ChainID.Hmy Local ,
* // chainType set to Woop
* chainType : ChainType.Woop ,
* // chainType set to Wiki Local
* chainId : ChainID.Wiki Local ,
* } ,
* ) ;
*
* const tmp = hmy . blockchain . syncing ( ) ;
* const tmp = wiki . blockchain . syncing ( ) ;
* console . log ( tmp )
* ` ` `
* /
@ -1296,18 +1296,18 @@ class Blockchain {
*
* @example
* ` ` ` javascript
* const hmy = new Harmony (
* const wiki = new Woop (
* // rpc url
* 'ws://api.s0.b.hmny.io/' ,
* {
* // chainType set to Harmony
* chainType : ChainType.Harmony ,
* // chainType set to Hmy Local
* chainId : ChainID.Hmy Local ,
* // chainType set to Woop
* chainType : ChainType.Woop ,
* // chainType set to Wiki Local
* chainId : ChainID.Wiki Local ,
* } ,
* ) ;
*
* const tmp = hmy . blockchain . logs ( {
* const tmp = wiki . blockchain . logs ( {
* from : '0x12'
* } ) ;
* console . log ( tmp )