@hashgraphonline/hashinal-wc 1.0.85 → 1.0.87
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/README.md +108 -0
- package/dist/es/hashinal-wc.es.js +120 -0
- package/dist/es/hashinal-wc.es.js.map +1 -1
- package/dist/es/index.d.ts +7 -2
- package/dist/es/types.d.ts +75 -2
- package/dist/index.d.ts +7 -2
- package/dist/types.d.ts +75 -2
- package/dist/umd/hashinal-wc.umd.js +6 -6
- package/dist/umd/hashinal-wc.umd.js.map +1 -1
- package/dist/umd/index.d.ts +7 -2
- package/dist/umd/types.d.ts +75 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -18,6 +18,10 @@ This SDK provides a simple interface for interacting with the Hedera Hashgraph u
|
|
|
18
18
|
- Dissociate tokens from accounts
|
|
19
19
|
- Update account properties
|
|
20
20
|
- Approve token allowances
|
|
21
|
+
- Get transaction details by transaction ID or timestamp from the mirror node
|
|
22
|
+
- Get account NFTs with optional filtering by token ID
|
|
23
|
+
- Validate NFT ownership by serial number and token ID
|
|
24
|
+
- Make read-only calls to smart contracts on the mirror node
|
|
21
25
|
|
|
22
26
|
## Installation
|
|
23
27
|
|
|
@@ -518,6 +522,109 @@ const tokens = await sdk.getAccountTokens(accountId);
|
|
|
518
522
|
console.log('Account tokens:', tokens);
|
|
519
523
|
```
|
|
520
524
|
|
|
525
|
+
### `getTransaction(transactionId: string)`
|
|
526
|
+
|
|
527
|
+
Retrieves transaction details by transaction ID from the mirror node.
|
|
528
|
+
|
|
529
|
+
UMD Example:
|
|
530
|
+
|
|
531
|
+
```javascript
|
|
532
|
+
const transactionId = "0.0.123456@1234567890.000000000";
|
|
533
|
+
const transaction = await window.HashinalsWalletConnectSDK.getTransaction(transactionId);
|
|
534
|
+
console.log(transaction);
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
ESM Example:
|
|
538
|
+
|
|
539
|
+
```javascript
|
|
540
|
+
const transaction = await sdk.getTransaction(transactionId);
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### `getTransactionByTimestamp(timestamp: string)`
|
|
544
|
+
|
|
545
|
+
Retrieves transaction details by consensus timestamp from the mirror node.
|
|
546
|
+
|
|
547
|
+
UMD Example:
|
|
548
|
+
|
|
549
|
+
```javascript
|
|
550
|
+
const timestamp = "1234567890.000000000";
|
|
551
|
+
const transaction = await window.HashinalsWalletConnectSDK.getTransactionByTimestamp(timestamp);
|
|
552
|
+
console.log(transaction);
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
ESM Example:
|
|
556
|
+
|
|
557
|
+
```javascript
|
|
558
|
+
const transaction = await sdk.getTransactionByTimestamp(timestamp);
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### `getAccountNFTs(accountId: string, tokenId?: string)`
|
|
562
|
+
|
|
563
|
+
Retrieves all NFTs owned by an account, with optional filtering by token ID.
|
|
564
|
+
|
|
565
|
+
UMD Example:
|
|
566
|
+
|
|
567
|
+
```javascript
|
|
568
|
+
const accountId = "0.0.123456";
|
|
569
|
+
const nfts = await window.HashinalsWalletConnectSDK.getAccountNFTs(accountId);
|
|
570
|
+
console.log(nfts);
|
|
571
|
+
|
|
572
|
+
// With token filter
|
|
573
|
+
const tokenId = "0.0.789012";
|
|
574
|
+
const filteredNfts = await window.HashinalsWalletConnectSDK.getAccountNFTs(accountId, tokenId);
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
ESM Example:
|
|
578
|
+
|
|
579
|
+
```javascript
|
|
580
|
+
const nfts = await sdk.getAccountNFTs(accountId);
|
|
581
|
+
const filteredNfts = await sdk.getAccountNFTs(accountId, tokenId);
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
### `validateNFTOwnership(serialNumber: string, accountId: string, tokenId: string)`
|
|
585
|
+
|
|
586
|
+
Validates if an account owns a specific NFT by serial number and token ID.
|
|
587
|
+
|
|
588
|
+
UMD Example:
|
|
589
|
+
|
|
590
|
+
```javascript
|
|
591
|
+
const serialNumber = "1";
|
|
592
|
+
const accountId = "0.0.123456";
|
|
593
|
+
const tokenId = "0.0.789012";
|
|
594
|
+
const nft = await window.HashinalsWalletConnectSDK.validateNFTOwnership(serialNumber, accountId, tokenId);
|
|
595
|
+
console.log(nft ? "Account owns this NFT" : "Account does not own this NFT");
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
ESM Example:
|
|
599
|
+
|
|
600
|
+
```javascript
|
|
601
|
+
const nft = await sdk.validateNFTOwnership(serialNumber, accountId, tokenId);
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### `readSmartContract(data: string, fromAccount: AccountId, contractId: ContractId, estimate?: boolean, value?: number)`
|
|
605
|
+
|
|
606
|
+
Makes a read-only call to a smart contract on the mirror node.
|
|
607
|
+
|
|
608
|
+
UMD Example:
|
|
609
|
+
|
|
610
|
+
```javascript
|
|
611
|
+
const data = "0x..."; // Contract call data
|
|
612
|
+
const fromAccount = window.HashgraphSDK.AccountId.fromString("0.0.123456");
|
|
613
|
+
const contractId = window.HashgraphSDK.ContractId.fromString("0.0.789012");
|
|
614
|
+
const result = await window.HashinalsWalletConnectSDK.readSmartContract(data, fromAccount, contractId);
|
|
615
|
+
console.log(result);
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
ESM Example:
|
|
619
|
+
|
|
620
|
+
```javascript
|
|
621
|
+
import { AccountId, ContractId } from '@hashgraph/sdk';
|
|
622
|
+
|
|
623
|
+
const fromAccount = AccountId.fromString("0.0.123456");
|
|
624
|
+
const contractId = ContractId.fromString("0.0.789012");
|
|
625
|
+
const result = await sdk.readSmartContract(data, fromAccount, contractId);
|
|
626
|
+
```
|
|
627
|
+
|
|
521
628
|
## Versions and Topic IDs
|
|
522
629
|
|
|
523
630
|
Version 1.0.58 and onward correlate with the NPM Package version.
|
|
@@ -532,6 +639,7 @@ Version 1.0.58 and onward correlate with the NPM Package version.
|
|
|
532
639
|
| v1.0.71 | 0.0.7337015 | UMD |
|
|
533
640
|
| v1.0.79 | 0.0.7473819 | UMD |
|
|
534
641
|
| v1.0.82 | 0.0.7522981 | UMD |
|
|
642
|
+
| v1.0.86 | 0.0.7770334 | UMD |
|
|
535
643
|
|
|
536
644
|
## Contributing
|
|
537
645
|
|
|
@@ -2371,6 +2371,126 @@ class HashinalsWalletConnectSDK {
|
|
|
2371
2371
|
throw error;
|
|
2372
2372
|
}
|
|
2373
2373
|
}
|
|
2374
|
+
async getTransaction(transactionId) {
|
|
2375
|
+
try {
|
|
2376
|
+
const networkPrefix = this.getNetworkPrefix();
|
|
2377
|
+
const url = `https://${networkPrefix}.mirrornode.hedera.com/api/v1/transactions/${transactionId}`;
|
|
2378
|
+
this.logger.debug("Fetching transaction", url);
|
|
2379
|
+
const request = await fetchWithRetry()(url);
|
|
2380
|
+
if (!request.ok) {
|
|
2381
|
+
throw new Error(`Failed to fetch transaction: ${request.status}`);
|
|
2382
|
+
}
|
|
2383
|
+
return await request.json();
|
|
2384
|
+
} catch (e) {
|
|
2385
|
+
this.logger.error("Failed to get transaction", e);
|
|
2386
|
+
return null;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
async getTransactionByTimestamp(timestamp) {
|
|
2390
|
+
var _a;
|
|
2391
|
+
try {
|
|
2392
|
+
const networkPrefix = this.getNetworkPrefix();
|
|
2393
|
+
const url = `https://${networkPrefix}.mirrornode.hedera.com/api/v1/transactions?timestamp=${timestamp}`;
|
|
2394
|
+
this.logger.debug("Fetching transaction by timestamp", url);
|
|
2395
|
+
const request = await fetchWithRetry()(url);
|
|
2396
|
+
if (!request.ok) {
|
|
2397
|
+
throw new Error(
|
|
2398
|
+
`Failed to fetch transaction by timestamp: ${request.status}`
|
|
2399
|
+
);
|
|
2400
|
+
}
|
|
2401
|
+
const response = await request.json();
|
|
2402
|
+
const transaction = (_a = response == null ? void 0 : response.transactions) == null ? void 0 : _a[0];
|
|
2403
|
+
if (transaction) {
|
|
2404
|
+
return await this.getTransaction(transaction.transaction_id);
|
|
2405
|
+
}
|
|
2406
|
+
return null;
|
|
2407
|
+
} catch (e) {
|
|
2408
|
+
this.logger.error("Failed to get transaction by timestamp", e);
|
|
2409
|
+
return null;
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
async getAccountNFTs(accountId, tokenId) {
|
|
2413
|
+
var _a, _b, _c;
|
|
2414
|
+
try {
|
|
2415
|
+
const networkPrefix = this.getNetworkPrefix();
|
|
2416
|
+
const tokenQuery = tokenId ? `&token.id=${tokenId}` : "";
|
|
2417
|
+
const url = `https://${networkPrefix}.mirrornode.hedera.com/api/v1/accounts/${accountId}/nfts?limit=200${tokenQuery}`;
|
|
2418
|
+
const request = await fetchWithRetry()(url);
|
|
2419
|
+
if (!request.ok) {
|
|
2420
|
+
throw new Error(`Failed to fetch NFTs for account: ${request.status}`);
|
|
2421
|
+
}
|
|
2422
|
+
const response = await request.json();
|
|
2423
|
+
let nextLink = ((_a = response == null ? void 0 : response.links) == null ? void 0 : _a.next) || null;
|
|
2424
|
+
let nfts = response.nfts;
|
|
2425
|
+
while (nextLink) {
|
|
2426
|
+
try {
|
|
2427
|
+
const nextRequest = await fetchWithRetry()(
|
|
2428
|
+
`https://${networkPrefix}.mirrornode.hedera.com${nextLink}`
|
|
2429
|
+
);
|
|
2430
|
+
if (!nextRequest.ok) {
|
|
2431
|
+
throw new Error(
|
|
2432
|
+
`Failed to fetch next page of NFTs: ${nextRequest.status}`
|
|
2433
|
+
);
|
|
2434
|
+
}
|
|
2435
|
+
const nextResponse = await nextRequest.json();
|
|
2436
|
+
nfts = [...nfts, ...(nextResponse == null ? void 0 : nextResponse.nfts) || []];
|
|
2437
|
+
nextLink = ((_b = nextResponse == null ? void 0 : nextResponse.links) == null ? void 0 : _b.next) && nextLink !== ((_c = nextResponse == null ? void 0 : nextResponse.links) == null ? void 0 : _c.next) ? nextResponse.links.next : null;
|
|
2438
|
+
} catch (e) {
|
|
2439
|
+
this.logger.error("Failed to fetch next page of NFTs", e);
|
|
2440
|
+
break;
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
return nfts.map((nft) => {
|
|
2444
|
+
try {
|
|
2445
|
+
nft.token_uri = Buffer$1.from(nft.metadata, "base64").toString("ascii");
|
|
2446
|
+
} catch (e) {
|
|
2447
|
+
this.logger.error("Failed to decode NFT metadata", e);
|
|
2448
|
+
}
|
|
2449
|
+
return nft;
|
|
2450
|
+
});
|
|
2451
|
+
} catch (e) {
|
|
2452
|
+
this.logger.error("Failed to get account NFTs", e);
|
|
2453
|
+
return [];
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
async validateNFTOwnership(serialNumber, accountId, tokenId) {
|
|
2457
|
+
const userNFTs = await this.getAccountNFTs(accountId, tokenId);
|
|
2458
|
+
return userNFTs.find(
|
|
2459
|
+
(nft) => nft.token_id === tokenId && nft.serial_number.toString() === serialNumber
|
|
2460
|
+
) || null;
|
|
2461
|
+
}
|
|
2462
|
+
async readSmartContract(data, fromAccount, contractId, estimate = true, value = 0) {
|
|
2463
|
+
try {
|
|
2464
|
+
const networkPrefix = this.getNetworkPrefix();
|
|
2465
|
+
const body = {
|
|
2466
|
+
block: "latest",
|
|
2467
|
+
data,
|
|
2468
|
+
estimate,
|
|
2469
|
+
from: fromAccount.toSolidityAddress(),
|
|
2470
|
+
to: contractId.toSolidityAddress(),
|
|
2471
|
+
value
|
|
2472
|
+
};
|
|
2473
|
+
if (!estimate) {
|
|
2474
|
+
body.gas = 3e5;
|
|
2475
|
+
body.gasPrice = 1e8;
|
|
2476
|
+
}
|
|
2477
|
+
const url = `https://${networkPrefix}.mirrornode.hedera.com/api/v1/contracts/call`;
|
|
2478
|
+
const response = await fetchWithRetry()(url, {
|
|
2479
|
+
method: "POST",
|
|
2480
|
+
body: JSON.stringify(body),
|
|
2481
|
+
headers: {
|
|
2482
|
+
"Content-Type": "application/json"
|
|
2483
|
+
}
|
|
2484
|
+
});
|
|
2485
|
+
if (!response.ok) {
|
|
2486
|
+
throw new Error(`Failed to make contract call: ${response.status}`);
|
|
2487
|
+
}
|
|
2488
|
+
return await response.json();
|
|
2489
|
+
} catch (e) {
|
|
2490
|
+
this.logger.error("Failed to make contract call", e);
|
|
2491
|
+
return null;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2374
2494
|
}
|
|
2375
2495
|
export {
|
|
2376
2496
|
HashgraphSDK,
|