I get output from the call at the console.log() but the function doesn't properly exit or end. I'm not too familiar with async functions, but when I take out the async I don't get any output.
const { Client, FileCreateTransaction, Ed25519PrivateKey, Hbar, FileContentsQuery, FileId } = require("@hashgraph/sdk");
require("dotenv").config();
async function makeFile(contents) {
const operatorAccount = process.env.OPERATOR_ID;
const operatorPrivateKey = Ed25519PrivateKey.fromString(process.env.OPERATOR_KEY);
const operatorPublicKey = operatorPrivateKey.publicKey;
if (operatorPrivateKey == null || operatorAccount == null) {
throw new Error(
"environment variables OPERATOR_KEY and OPERATOR_ID must be present"
);
}
const client = Client.forTestnet()
client.setOperator(operatorAccount, operatorPrivateKey);
// make new file
const transactionId = await new FileCreateTransaction()
.setContents(contents)
.addKey(operatorPublicKey) // Defines the "admin" of this file
.setMaxTransactionFee(new Hbar(15))
.execute(client);
const receipt = await transactionId.getReceipt(client);
const fileId = receipt.getFileId();
return fileId;
}
async function main()
{
let id = await makeFile(process.argv[2]);
console.log(id);
return id;
}
main()
EDIT: So it does fully run, but it takes a while (over a minute or so) which is really impractical actually.