Skip to content

Commit 9d1b2c9

Browse files
authored
Merge pull request #75 from solana-developers/node-imports
fix node imports for anchor functions
2 parents 4fffc8f + fc17b60 commit 9d1b2c9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## 2.7
22

33
- Added `sendTransaction()` to send transactions with compute unit optimization and automatic retries.
4-
- Removed `sendTransactionWithRetry()` as sendTransaction() is more convenient.
4+
- Removed `sendTransactionWithRetry()` as `sendTransaction()` is more convenient.
5+
- Fixed the node specific imports for the Anchor transaction helpers
56

67
## 2.6
78

src/lib/transaction.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import {
2323
BorshInstructionCoder,
2424
} from "@coral-xyz/anchor";
2525
import BN from "bn.js";
26-
import * as fs from "fs";
27-
import * as path from "path";
2826

2927
export const confirmTransaction = async (
3028
connection: Connection,
@@ -387,6 +385,9 @@ export async function getIdlParsedAccountData<T = any>(
387385
accountAddress: PublicKey,
388386
connection?: Connection,
389387
): Promise<T> {
388+
const fs = await import("node:fs");
389+
const path = await import("node:path");
390+
390391
// Load and parse IDL file
391392
const idlFile = fs.readFileSync(path.resolve(idlPath), "utf8");
392393
const idl = JSON.parse(idlFile) as Idl;
@@ -426,6 +427,9 @@ export async function parseAnchorTransactionEvents(
426427
data: any;
427428
}>
428429
> {
430+
const fs = await import("node:fs");
431+
const path = await import("node:path");
432+
429433
const idlFile = fs.readFileSync(path.resolve(idlPath), "utf8");
430434
const idl = JSON.parse(idlFile) as Idl;
431435

@@ -493,6 +497,9 @@ export async function decodeAnchorTransaction(
493497
signature: string,
494498
connection?: Connection,
495499
): Promise<DecodedTransaction> {
500+
const fs = await import("node:fs");
501+
const path = await import("node:path");
502+
496503
const idlFile = fs.readFileSync(path.resolve(idlPath), "utf8");
497504
const idl = JSON.parse(idlFile) as Idl;
498505

0 commit comments

Comments
 (0)