Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@harmony-js/transaction

Package Overview
Dependencies
Maintainers
3
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmony-js/transaction - npm Package Compare versions

Comparing version 0.1.55 to 0.1.56

0

dist/abstractTransaction.d.ts

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

228

dist/types.d.ts
/**
* ## About this package
# @harmony-js/transaction
This package provides a collection of apis to create, sign/send transaction, and receive confirm/receipt.
## Installation
```
npm install @harmony-js/transaction
```
## Usage
Create a Harmony instance connecting to testnet
```javascript
* const { Harmony } = require('@harmony-js/core');
* const {
* ChainID,
* ChainType,
* hexToNumber,
* numberToHex,
* fromWei,
* Units,
* Unit,
* } = require('@harmony-js/utils');
* const hmy = new Harmony(
* 'https://api.s0.b.hmny.io/',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyTestnet,
* },
* );
```
Creating a new transaction using parameters
```javascript
* const txn = hmy.transactions.newTx({
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
* value: new Unit(1).asOne().toWei(),
* // gas limit, you can use string
* gasLimit: '21000',
* // 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('1').asGwei().toWei(),
* });
```
Recovering transaction from raw transaction hash
```javascript
* const raw = '0xf86d21843b9aca00825208808094d6ba69da5b45ec98b53e3258d7de756a567b6763880de0b6b3a76400008028a0da8887719f377401963407fc1d82d2ab52404600cf7bea37c27bd2dfd7c86aaaa03c405b0843394442b303256a804bde835821a8a77bd88a2ced9ffdc8b0a409e9';
* const tx = hmy.transactions.recover(raw);
```
Getting the RLP encoding of a transaction (rawTransaction), along with raw transaction field values that were encoded
```javascript
* const [encoded, raw] = txn.getRLPUnsigned()
```
Sign the transaction using a wallet and send the transaction, wait for confirmation and print receipt
```javascript
* // key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
* hmy.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');
* hmy.wallet.signTransaction(txn).then(signedTxn => {
* signedTxn.sendTransaction().then(([tx, hash]) => {
* console.log('tx hash: ' + hash);
* signedTxn.confirm(hash).then(response => {
* console.log(response.receipt);
* });
* });
* });
```
Asynchronous transaction sign, send, and confirm
```javascript
* async function transfer() {
* hmy.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');
* const signedTxn = await hmy.wallet.signTransaction(txn);
* signedTxn
* .observed()
* .on('transactionHash', (txnHash) => {
* console.log('');
* console.log('--- hash ---');
* console.log('');
* console.log(txnHash);
* console.log('');
* })
* .on('receipt', (receipt) => {
* console.log('');
* console.log('--- receipt ---');
* console.log('');
* console.log(receipt);
* console.log('');
* })
* .on('cxReceipt', (receipt) => {
* console.log('');
* console.log('--- cxReceipt ---');
* console.log('');
* console.log(receipt);
* console.log('');
* })
* .on('error', (error) => {
* console.log('');
* console.log('--- error ---');
* console.log('');
* console.log(error);
* console.log('');
* });
* const [sentTxn, txnHash] = await signedTxn.sendTransaction();
* const confiremdTxn = await sentTxn.confirm(txnHash);
* // if the transactino is cross-shard transaction
* if (!confiremdTxn.isCrossShard()) {
* if (confiremdTxn.isConfirmed()) {
* console.log('--- Result ---');
* console.log('');
* console.log('Normal transaction');
* console.log(`${txnHash} is confirmed`);
* console.log('');
* console.log('please see detail in explorer:');
* console.log('');
* console.log('https://explorer.testnet.harmony.one/#/tx/' + txnHash);
* console.log('');
* process.exit();
* }
* }
* if (confiremdTxn.isConfirmed() && confiremdTxn.isCxConfirmed()) {
* console.log('--- Result ---');
* console.log('');
* console.log('Cross-Shard transaction');
* console.log(`${txnHash} is confirmed`);
* console.log('');
* console.log('please see detail in explorer:');
* console.log('');
* console.log('https://explorer.testnet.harmony.one/#/tx/' + txnHash);
* console.log('');
* process.exit();
* }
* }
* transfer();
```
*
* `@harmony-js/transaction` provides the functions to build transactions
*
* Develop can use this package to:
* - build a transaction offline!
* - set params of transaction
* -
*
* ## How to use this package
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: build a transaction
* ```javascript
* const txn = hmy.transactions.newTx({
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
* value: '10000',
* gasLimit: '210000',
* shardID: 0,
* toShardID: 0,
* gasPrice: new hmy.utils.Unit('100').asGwei().toWei(),
* });
* ```
*
* ## some important information
* Transaction Parameters
* ```java
* // interface TxParams
* id: string;
* from: string;
* to: string;
* nonce: number | string;
* gasLimit: number | string | BN;
* gasPrice: number | string | BN;
* shardID: number | string;
* toShardID: number | string;
* data: string;
* value: number | string | BN;
* chainId: number;
* rawTransaction: string;
* unsignedRawTransaction: string;
* signature: Signature;
* receipt?: TransasctionReceipt;
* ```
*
* Transaction Receipt
* ```java
* // interface TransasctionReceipt
* transactionHash: string;
* transactionIndex: string;
* blockHash: string;
* blockNumber: string; // 11
* from: string;
* to: string;
* gasUsed: string;
* cumulativeGasUsed: string; // 13244
* contractAddress?: string | null; // or null, if none was created
* logs: any[];
* logsBloom: string; // 256 byte bloom filter
* v: string;
* r: string;
* s: string;
* responseType?: string;
* byzantium?: boolean;
* status?: string; // post Byzantium will return `0x0` or `0x1`
* root?: string; // pre Byzantium will return `root`
* ```
*
* @packageDocumentation

@@ -84,0 +152,0 @@ * @module harmony-transaction

"use strict";
/**
* ## About this package
# @harmony-js/transaction
This package provides a collection of apis to create, sign/send transaction, and receive confirm/receipt.
## Installation
```
npm install @harmony-js/transaction
```
## Usage
Create a Harmony instance connecting to testnet
```javascript
* const { Harmony } = require('@harmony-js/core');
* const {
* ChainID,
* ChainType,
* hexToNumber,
* numberToHex,
* fromWei,
* Units,
* Unit,
* } = require('@harmony-js/utils');
* const hmy = new Harmony(
* 'https://api.s0.b.hmny.io/',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyTestnet,
* },
* );
```
Creating a new transaction using parameters
```javascript
* const txn = hmy.transactions.newTx({
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
* value: new Unit(1).asOne().toWei(),
* // gas limit, you can use string
* gasLimit: '21000',
* // 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('1').asGwei().toWei(),
* });
```
Recovering transaction from raw transaction hash
```javascript
* const raw = '0xf86d21843b9aca00825208808094d6ba69da5b45ec98b53e3258d7de756a567b6763880de0b6b3a76400008028a0da8887719f377401963407fc1d82d2ab52404600cf7bea37c27bd2dfd7c86aaaa03c405b0843394442b303256a804bde835821a8a77bd88a2ced9ffdc8b0a409e9';
* const tx = hmy.transactions.recover(raw);
```
Getting the RLP encoding of a transaction (rawTransaction), along with raw transaction field values that were encoded
```javascript
* const [encoded, raw] = txn.getRLPUnsigned()
```
Sign the transaction using a wallet and send the transaction, wait for confirmation and print receipt
```javascript
* // key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
* hmy.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');
* hmy.wallet.signTransaction(txn).then(signedTxn => {
* signedTxn.sendTransaction().then(([tx, hash]) => {
* console.log('tx hash: ' + hash);
* signedTxn.confirm(hash).then(response => {
* console.log(response.receipt);
* });
* });
* });
```
Asynchronous transaction sign, send, and confirm
```javascript
* async function transfer() {
* hmy.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');
* const signedTxn = await hmy.wallet.signTransaction(txn);
* signedTxn
* .observed()
* .on('transactionHash', (txnHash) => {
* console.log('');
* console.log('--- hash ---');
* console.log('');
* console.log(txnHash);
* console.log('');
* })
* .on('receipt', (receipt) => {
* console.log('');
* console.log('--- receipt ---');
* console.log('');
* console.log(receipt);
* console.log('');
* })
* .on('cxReceipt', (receipt) => {
* console.log('');
* console.log('--- cxReceipt ---');
* console.log('');
* console.log(receipt);
* console.log('');
* })
* .on('error', (error) => {
* console.log('');
* console.log('--- error ---');
* console.log('');
* console.log(error);
* console.log('');
* });
* const [sentTxn, txnHash] = await signedTxn.sendTransaction();
* const confiremdTxn = await sentTxn.confirm(txnHash);
* // if the transactino is cross-shard transaction
* if (!confiremdTxn.isCrossShard()) {
* if (confiremdTxn.isConfirmed()) {
* console.log('--- Result ---');
* console.log('');
* console.log('Normal transaction');
* console.log(`${txnHash} is confirmed`);
* console.log('');
* console.log('please see detail in explorer:');
* console.log('');
* console.log('https://explorer.testnet.harmony.one/#/tx/' + txnHash);
* console.log('');
* process.exit();
* }
* }
* if (confiremdTxn.isConfirmed() && confiremdTxn.isCxConfirmed()) {
* console.log('--- Result ---');
* console.log('');
* console.log('Cross-Shard transaction');
* console.log(`${txnHash} is confirmed`);
* console.log('');
* console.log('please see detail in explorer:');
* console.log('');
* console.log('https://explorer.testnet.harmony.one/#/tx/' + txnHash);
* console.log('');
* process.exit();
* }
* }
* transfer();
```
*
* `@harmony-js/transaction` provides the functions to build transactions
*
* Develop can use this package to:
* - build a transaction offline!
* - set params of transaction
* -
*
* ## How to use this package
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: build a transaction
* ```javascript
* const txn = hmy.transactions.newTx({
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
* value: '10000',
* gasLimit: '210000',
* shardID: 0,
* toShardID: 0,
* gasPrice: new hmy.utils.Unit('100').asGwei().toWei(),
* });
* ```
*
* ## some important information
* Transaction Parameters
* ```java
* // interface TxParams
* id: string;
* from: string;
* to: string;
* nonce: number | string;
* gasLimit: number | string | BN;
* gasPrice: number | string | BN;
* shardID: number | string;
* toShardID: number | string;
* data: string;
* value: number | string | BN;
* chainId: number;
* rawTransaction: string;
* unsignedRawTransaction: string;
* signature: Signature;
* receipt?: TransasctionReceipt;
* ```
*
* Transaction Receipt
* ```java
* // interface TransasctionReceipt
* transactionHash: string;
* transactionIndex: string;
* blockHash: string;
* blockNumber: string; // 11
* from: string;
* to: string;
* gasUsed: string;
* cumulativeGasUsed: string; // 13244
* contractAddress?: string | null; // or null, if none was created
* logs: any[];
* logsBloom: string; // 256 byte bloom filter
* v: string;
* r: string;
* s: string;
* responseType?: string;
* byzantium?: boolean;
* status?: string; // post Byzantium will return `0x0` or `0x1`
* root?: string; // pre Byzantium will return `root`
* ```
*
* @packageDocumentation

@@ -85,0 +153,0 @@ * @module harmony-transaction

@@ -0,0 +0,0 @@ /**

{
"name": "@harmony-js/transaction",
"version": "0.1.55",
"version": "0.1.56",
"description": "transaction package for harmony",

@@ -21,7 +21,7 @@ "main": "dist/index.js",

"dependencies": {
"@harmony-js/crypto": "0.1.55",
"@harmony-js/network": "0.1.55",
"@harmony-js/utils": "0.1.55"
"@harmony-js/crypto": "0.1.56",
"@harmony-js/network": "0.1.56",
"@harmony-js/utils": "0.1.56"
},
"gitHead": "c49abc56916e6edf7aa959e38397ff280e47ec30"
"gitHead": "8f8e17fdaed394af1c28cd133d6018bf48915a81"
}
/**
* ## About this package
# @harmony-js/transaction
This package provides a collection of apis to create, sign/send transaction, and receive confirm/receipt.
## Installation
```
npm install @harmony-js/transaction
```
## Usage
Create a Harmony instance connecting to testnet
```javascript
* const { Harmony } = require('@harmony-js/core');
* const {
* ChainID,
* ChainType,
* hexToNumber,
* numberToHex,
* fromWei,
* Units,
* Unit,
* } = require('@harmony-js/utils');
* const hmy = new Harmony(
* 'https://api.s0.b.hmny.io/',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyTestnet,
* },
* );
```
Creating a new transaction using parameters
```javascript
* const txn = hmy.transactions.newTx({
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
* value: new Unit(1).asOne().toWei(),
* // gas limit, you can use string
* gasLimit: '21000',
* // 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('1').asGwei().toWei(),
* });
```
Recovering transaction from raw transaction hash
```javascript
* const raw = '0xf86d21843b9aca00825208808094d6ba69da5b45ec98b53e3258d7de756a567b6763880de0b6b3a76400008028a0da8887719f377401963407fc1d82d2ab52404600cf7bea37c27bd2dfd7c86aaaa03c405b0843394442b303256a804bde835821a8a77bd88a2ced9ffdc8b0a409e9';
* const tx = hmy.transactions.recover(raw);
```
Getting the RLP encoding of a transaction (rawTransaction), along with raw transaction field values that were encoded
```javascript
* const [encoded, raw] = txn.getRLPUnsigned()
```
Sign the transaction using a wallet and send the transaction, wait for confirmation and print receipt
```javascript
* // key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance
* hmy.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');
* hmy.wallet.signTransaction(txn).then(signedTxn => {
* signedTxn.sendTransaction().then(([tx, hash]) => {
* console.log('tx hash: ' + hash);
* signedTxn.confirm(hash).then(response => {
* console.log(response.receipt);
* });
* });
* });
```
Asynchronous transaction sign, send, and confirm
```javascript
* async function transfer() {
* hmy.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');
* const signedTxn = await hmy.wallet.signTransaction(txn);
* signedTxn
* .observed()
* .on('transactionHash', (txnHash) => {
* console.log('');
* console.log('--- hash ---');
* console.log('');
* console.log(txnHash);
* console.log('');
* })
* .on('receipt', (receipt) => {
* console.log('');
* console.log('--- receipt ---');
* console.log('');
* console.log(receipt);
* console.log('');
* })
* .on('cxReceipt', (receipt) => {
* console.log('');
* console.log('--- cxReceipt ---');
* console.log('');
* console.log(receipt);
* console.log('');
* })
* .on('error', (error) => {
* console.log('');
* console.log('--- error ---');
* console.log('');
* console.log(error);
* console.log('');
* });
* const [sentTxn, txnHash] = await signedTxn.sendTransaction();
* const confiremdTxn = await sentTxn.confirm(txnHash);
* // if the transactino is cross-shard transaction
* if (!confiremdTxn.isCrossShard()) {
* if (confiremdTxn.isConfirmed()) {
* console.log('--- Result ---');
* console.log('');
* console.log('Normal transaction');
* console.log(`${txnHash} is confirmed`);
* console.log('');
* console.log('please see detail in explorer:');
* console.log('');
* console.log('https://explorer.testnet.harmony.one/#/tx/' + txnHash);
* console.log('');
* process.exit();
* }
* }
* if (confiremdTxn.isConfirmed() && confiremdTxn.isCxConfirmed()) {
* console.log('--- Result ---');
* console.log('');
* console.log('Cross-Shard transaction');
* console.log(`${txnHash} is confirmed`);
* console.log('');
* console.log('please see detail in explorer:');
* console.log('');
* console.log('https://explorer.testnet.harmony.one/#/tx/' + txnHash);
* console.log('');
* process.exit();
* }
* }
* transfer();
```
*
* `@harmony-js/transaction` provides the functions to build transactions
*
* Develop can use this package to:
* - build a transaction offline!
* - set params of transaction
* -
*
* ## How to use this package
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: build a transaction
* ```javascript
* const txn = hmy.transactions.newTx({
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2',
* value: '10000',
* gasLimit: '210000',
* shardID: 0,
* toShardID: 0,
* gasPrice: new hmy.utils.Unit('100').asGwei().toWei(),
* });
* ```
*
* ## some important information
* Transaction Parameters
* ```java
* // interface TxParams
* id: string;
* from: string;
* to: string;
* nonce: number | string;
* gasLimit: number | string | BN;
* gasPrice: number | string | BN;
* shardID: number | string;
* toShardID: number | string;
* data: string;
* value: number | string | BN;
* chainId: number;
* rawTransaction: string;
* unsignedRawTransaction: string;
* signature: Signature;
* receipt?: TransasctionReceipt;
* ```
*
* Transaction Receipt
* ```java
* // interface TransasctionReceipt
* transactionHash: string;
* transactionIndex: string;
* blockHash: string;
* blockNumber: string; // 11
* from: string;
* to: string;
* gasUsed: string;
* cumulativeGasUsed: string; // 13244
* contractAddress?: string | null; // or null, if none was created
* logs: any[];
* logsBloom: string; // 256 byte bloom filter
* v: string;
* r: string;
* s: string;
* responseType?: string;
* byzantium?: boolean;
* status?: string; // post Byzantium will return `0x0` or `0x1`
* root?: string; // pre Byzantium will return `root`
* ```
*
* @packageDocumentation

@@ -84,0 +152,0 @@ * @module harmony-transaction

@@ -40,3 +40,3 @@ /**

id: 1,
result: '0x666666666666',
result: 1,
},

@@ -46,7 +46,2 @@ {

id: 1,
result: '0x1',
},
{
jsonrpc: '2.0',
id: 1,
result: '0x7e1ef610f700805b93cf85b1e55bce84fcbd04373252a968755366a8d2215424',

@@ -53,0 +48,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc