JavaScript code for test Hedrea SDK
This package is just deploy one simple smart contract generated by the following Solidity code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HelloWorld {
function sayHello() public pure returns (string memory) {
return "Hello World";
}
}
But trying to deploy the generated bytecode seems not easy. The current Hedra JS SDK version is: 2.35.0 My Node.js version: 20.5.0 My OS: Window 10 (22H2)
But the following AccountBalance.js code works:
const { AccountBalanceQuery, LocalProvider, Wallet } = require("@hashgraph/sdk"); const dotenv = require("dotenv");
dotenv.config();
async function main() { if (process.env.OPERATOR_ID == null || process.env.OPERATOR_KEY == null) { throw new Error( "Environment variables OPERATOR_ID, and OPERATOR_KEY are required." ); }
const wallet = new Wallet(
process.env.OPERATOR_ID,
process.env.OPERATOR_KEY,
new LocalProvider()
);
const balance = await new AccountBalanceQuery()
.setAccountId(wallet.getAccountId())
.executeWithSigner(wallet);
console.log(
`${wallet
.getAccountId()
.toString()} balance = ${balance.hbars.toString()}`
);
}
void main();
setTimeout(() => { process.exit(0); }, 3000);
The result of running AccountBalance.js: PS D:\nodejs\hedra-project> node .\AccountBalance.js 0.0.4470974 balance = 10000 ℏ PS D:\nodejs\hedra-project>