@transak/hedera-transak 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +2 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +46 -35
- package/lib/types.d.ts +2 -5
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +5 -4
- package/package.json +2 -1
package/lib/config.js
CHANGED
|
@@ -5,12 +5,14 @@ exports.networks = {
|
|
|
5
5
|
main: {
|
|
6
6
|
transactionLink: hash => `https://hederaexplorer.io/search-details/transaction/${hash}`,
|
|
7
7
|
walletLink: address => `https://hederaexplorer.io/search-details/account/${address}`,
|
|
8
|
+
mirrorNodeUrl: 'https://mainnet-public.mirrornode.hedera.com/api/v1/transactions/',
|
|
8
9
|
networkName: 'mainnet',
|
|
9
10
|
},
|
|
10
11
|
testnet: {
|
|
11
12
|
transactionLink: hash => `https://testnet.hederaexplorer.io/search-details/transaction/${hash}`,
|
|
12
13
|
walletLink: address => `https://testnet.hederaexplorer.io/search-details/account/${address}`,
|
|
13
14
|
networkName: 'testnet',
|
|
15
|
+
mirrorNodeUrl: 'https://testnet.mirrornode.hedera.com/api/v1/transactions/',
|
|
14
16
|
},
|
|
15
17
|
};
|
|
16
18
|
module.exports = { networks: exports.networks };
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { GetTransactionResult, SendTransactionResult, SendTransactionParams } fr
|
|
|
4
4
|
* @param network
|
|
5
5
|
* @param privateKey
|
|
6
6
|
* @param accountId
|
|
7
|
-
* @param
|
|
7
|
+
* @param userAccountId // user account id
|
|
8
|
+
* @param tokenId
|
|
8
9
|
* @returns
|
|
9
10
|
*/
|
|
10
11
|
declare function isTokenAssociated(network: string, privateKey: string, accountId: string, userAccountId: string, tokenId: string): Promise<boolean>;
|
|
@@ -20,9 +21,10 @@ declare function isTokenAssociated(network: string, privateKey: string, accountI
|
|
|
20
21
|
declare function getBalance(network: string, decimals: number, privateKey: string, accountId: string, tokenId?: string): Promise<number>;
|
|
21
22
|
/**
|
|
22
23
|
* Get the transaction details by transaction id
|
|
23
|
-
* @param
|
|
24
|
+
* @param txnId
|
|
24
25
|
* @param network
|
|
25
|
-
* @param
|
|
26
|
+
* @param privateKey
|
|
27
|
+
* @param accountId
|
|
26
28
|
* @returns
|
|
27
29
|
*/
|
|
28
30
|
declare function getTransaction(txnId: string, network: string, privateKey: string, accountId: string): Promise<GetTransactionResult | null>;
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
15
|
const config_1 = require("./config");
|
|
12
16
|
const utils_1 = require("./utils");
|
|
13
17
|
const sdk_1 = require("@hashgraph/sdk");
|
|
@@ -61,7 +65,8 @@ function getClient(network, privateKey, accountId) {
|
|
|
61
65
|
* @param network
|
|
62
66
|
* @param privateKey
|
|
63
67
|
* @param accountId
|
|
64
|
-
* @param
|
|
68
|
+
* @param userAccountId // user account id
|
|
69
|
+
* @param tokenId
|
|
65
70
|
* @returns
|
|
66
71
|
*/
|
|
67
72
|
function isTokenAssociated(network, privateKey, accountId, userAccountId, tokenId) {
|
|
@@ -101,42 +106,49 @@ function getBalance(network, decimals, privateKey, accountId, tokenId) {
|
|
|
101
106
|
}
|
|
102
107
|
/**
|
|
103
108
|
* Get the transaction details by transaction id
|
|
104
|
-
* @param
|
|
109
|
+
* @param txnId
|
|
105
110
|
* @param network
|
|
106
|
-
* @param
|
|
111
|
+
* @param privateKey
|
|
112
|
+
* @param accountId
|
|
107
113
|
* @returns
|
|
108
114
|
*/
|
|
109
115
|
function getTransaction(txnId, network, privateKey, accountId) {
|
|
110
|
-
var _a, _b, _c;
|
|
111
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
117
|
+
try {
|
|
118
|
+
const { mirrorNodeUrl } = getNetwork(network);
|
|
119
|
+
if (txnId.includes('@')) {
|
|
120
|
+
txnId = (0, utils_1._getTransactionNumber)(txnId);
|
|
121
|
+
}
|
|
122
|
+
const response = yield (0, axios_1.default)({
|
|
123
|
+
method: 'get',
|
|
124
|
+
url: mirrorNodeUrl + txnId,
|
|
125
|
+
headers: {
|
|
126
|
+
accept: 'application/json',
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
const transactionData = response.data.transactions[0];
|
|
130
|
+
return {
|
|
131
|
+
transactionData,
|
|
132
|
+
receipt: {
|
|
133
|
+
date: transactionData.consensus_timestamp,
|
|
134
|
+
gasCostCryptoCurrency: 'HBAR',
|
|
135
|
+
gasCostInCrypto: +(0, utils_1._toDecimal)(transactionData.charged_tx_fee.toString(), 8),
|
|
136
|
+
gasLimit: +(0, utils_1._toDecimal)(transactionData.max_fee.toString(), 8),
|
|
137
|
+
isPending: false,
|
|
138
|
+
isExecuted: true,
|
|
139
|
+
isSuccessful: transactionData.result === 'SUCCESS',
|
|
140
|
+
isFailed: transactionData.result !== 'SUCCESS',
|
|
141
|
+
isInvalid: transactionData.result !== 'SUCCESS',
|
|
142
|
+
network,
|
|
143
|
+
nonce: transactionData.nonce || 0,
|
|
144
|
+
transactionHash: transactionData.transaction_id,
|
|
145
|
+
transactionLink: getTransactionLink(txnId, network),
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
140
152
|
});
|
|
141
153
|
}
|
|
142
154
|
/**
|
|
@@ -179,9 +191,8 @@ function sendTransaction({ to, amount, network, accountId, privateKey, decimals,
|
|
|
179
191
|
network,
|
|
180
192
|
nonce: ((_b = sendTransactionResponse.transactionId.nonce) === null || _b === void 0 ? void 0 : _b.toNumber()) || 0,
|
|
181
193
|
to,
|
|
182
|
-
transactionHash: sendTransactionResponse.
|
|
183
|
-
|
|
184
|
-
transactionLink: getTransactionLink(sendTransactionResponse.transactionId.toString(), network),
|
|
194
|
+
transactionHash: (0, utils_1._getTransactionNumber)(sendTransactionResponse.transactionId.toString()),
|
|
195
|
+
transactionLink: getTransactionLink((0, utils_1._getTransactionNumber)(sendTransactionResponse.transactionId.toString()), network),
|
|
185
196
|
},
|
|
186
197
|
};
|
|
187
198
|
});
|
package/lib/types.d.ts
CHANGED
|
@@ -3,13 +3,12 @@ export declare type Network = {
|
|
|
3
3
|
networkName: string;
|
|
4
4
|
transactionLink: (arg0: string) => string;
|
|
5
5
|
walletLink: (arg0: string) => string;
|
|
6
|
+
mirrorNodeUrl: string;
|
|
6
7
|
};
|
|
7
8
|
export declare type GetTransactionResult = {
|
|
8
9
|
transactionData: TransactionRecord;
|
|
9
10
|
receipt: {
|
|
10
|
-
amount: number;
|
|
11
11
|
date: Date | null;
|
|
12
|
-
from: string;
|
|
13
12
|
gasCostCryptoCurrency: string;
|
|
14
13
|
gasCostInCrypto: number;
|
|
15
14
|
gasLimit: number;
|
|
@@ -21,7 +20,6 @@ export declare type GetTransactionResult = {
|
|
|
21
20
|
network: string;
|
|
22
21
|
nonce: number;
|
|
23
22
|
transactionHash: string;
|
|
24
|
-
transactionId: string;
|
|
25
23
|
transactionLink: string;
|
|
26
24
|
};
|
|
27
25
|
};
|
|
@@ -44,9 +42,8 @@ export declare type SendTransactionResult = {
|
|
|
44
42
|
network: string;
|
|
45
43
|
nonce: number;
|
|
46
44
|
to: string;
|
|
47
|
-
transactionHash:
|
|
45
|
+
transactionHash: string;
|
|
48
46
|
transactionLink: string;
|
|
49
|
-
transactionId: string;
|
|
50
47
|
transactionReceipt: TransactionReceipt;
|
|
51
48
|
};
|
|
52
49
|
};
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BigNumber } from '@hashgraph/hethers';
|
|
2
2
|
export declare const _toDecimal: (amount: string, decimals: number) => string;
|
|
3
3
|
export declare const _toCrypto: (amount: string, decimals: number) => BigNumber;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const _getTransactionNumber: (txnId: string) => string;
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports._getTransactionNumber = exports._toCrypto = exports._toDecimal = void 0;
|
|
4
4
|
const hethers_1 = require("@hashgraph/hethers");
|
|
5
5
|
// converts any units to Hbars
|
|
6
6
|
const _toDecimal = (amount, decimals) => {
|
|
@@ -11,8 +11,9 @@ exports._toDecimal = _toDecimal;
|
|
|
11
11
|
// converts Hbar to tinybar
|
|
12
12
|
const _toCrypto = (amount, decimals) => hethers_1.hethers.utils.parseUnits(amount, decimals);
|
|
13
13
|
exports._toCrypto = _toCrypto;
|
|
14
|
-
const
|
|
14
|
+
const _getTransactionNumber = (txnId) => {
|
|
15
15
|
const [accountId, rest] = txnId.split('@');
|
|
16
|
-
|
|
16
|
+
const [realm, timestamp] = rest.split('.');
|
|
17
|
+
return [accountId, realm, timestamp].join('-');
|
|
17
18
|
};
|
|
18
|
-
exports.
|
|
19
|
+
exports._getTransactionNumber = _getTransactionNumber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transak/hedera-transak",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@ethersproject/wordlists": "^5.7.0",
|
|
33
33
|
"@hashgraph/hethers": "^1.2.1",
|
|
34
34
|
"@hashgraph/sdk": "^2.18.1",
|
|
35
|
+
"axios": "^0.27.2",
|
|
35
36
|
"dotenv": "10.0.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|