I’m new to node,js,typescript and NPM as a whole, I need a certain funtionality in a discord bot I’m building and only sdk I found to get it is in typescript which is a whole new world for me,
I’m trying to read a file using fs.readFile
here is the code:
import { readFile } from "fs";
import { Connection, Keypair } from "@solana/web3.js";
import { getOrca, OrcaFarmConfig, OrcaPoolConfig } from "@orca-so/sdk";
import Decimal from "decimal.js";
//console.log('test');
const main = async() => {
const secretKeyString = readFile("lp.json", (error, data) => data);
const secretKey = Uint8Array.from(JSON.parse(secretKeyString));
const owner = Keypair.fromSecretKey(secretKey);
}
I’m getting a problem:
Argument of type 'void' is not assignable to parameter of type 'string'.
ik that the function is async but I’m not familliar with asyncio in javascript so how can I resolve this?
>Solution :
You should use readFileSync here as it will serve the purpose you need in that context.
import { readFile } from "fs";
import { Connection, Keypair } from "@solana/web3.js";
import { getOrca, OrcaFarmConfig, OrcaPoolConfig } from "@orca-so/sdk";
import Decimal from "decimal.js";
//console.log('test');
const main = async() => {
const secretKeyString = readFileSync("lp.json", {
encoding: "utf-8",
});
const secretKey = Uint8Array.from(JSON.parse(secretKeyString));
const owner = Keypair.fromSecretKey(secretKey);
}