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