-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
The following code is incorrect:
const {
AccountId,
PrivateKey,
Client,
Hbar,
HbarUnit
} = require("@hashgraph/sdk"); // v2.46.0
async function main() {
let client;
try {
// Your account ID and private key from string value
const MY_ACCOUNT_ID = AccountId.fromString("0.0.3777791");
const MY_PRIVATE_KEY = PrivateKey.fromStringED25519("3f918872e45c0b594031c1d7edccbdae4b784ecdfbc67f4b844d31c6ee96ef8d");
// Pre-configured client for test network (testnet)
client = Client.forTestnet();
//Set the operator with the account ID and private key
client.setOperator(MY_ACCOUNT_ID, MY_PRIVATE_KEY);
// Start your code here
// 10 HBAR
new Hbar(10);
//10 HBAR
Hbar.from(10);
//100 tinybars
Hbar.from(100, HbarUnit.Tinybar);
// 10 HBAR converted from string value
Hbar.fromString("10");
//100 tinybars from string value
Hbar.fromString("100", HbarUnit.Tinybar);
//10 HBAR converted to tinybars
new Hbar(10).to(HbarUnit.TINYBAR);
//10 HBAR converted to tinybars
new Hbar(10).toString(HbarUnit.Tinybar);
//10 HBAR converted to tinybars
new Hbar(10).toTinybars();
} catch (error) {
console.error(error);
} finally {
if (client) client.close();
}
}
main();
This should be:
const {
AccountId,
PrivateKey,
Client,
Hbar,
HbarUnit
} = require("@hashgraph/sdk"); // v2.46.0
async function main() {
let client;
try {
// Your account ID and private key from string value
const MY_ACCOUNT_ID = AccountId.fromString("0.0.3777791");
const MY_PRIVATE_KEY = PrivateKey.fromStringED25519("3f918872e45c0b594031c1d7edccbdae4b784ecdfbc67f4b844d31c6ee96ef8d");
// Pre-configured client for test network (testnet)
client = Client.forTestnet();
//Set the operator with the account ID and private key
client.setOperator(MY_ACCOUNT_ID, MY_PRIVATE_KEY);
// Start your code here
// 10 HBAR
new Hbar(10);
//10 HBAR
Hbar.from(10);
//100 tinybars
Hbar.from(100, HbarUnit.Tinybar);
// 10 HBAR converted from string value
Hbar.fromString("10");
//100 tinybars from string value
Hbar.fromString("100", HbarUnit.Tinybar);
//10 HBAR converted to tinybars
new Hbar(10).to(HbarUnit.Tinybar);
//10 HBAR converted to tinybars
new Hbar(10).toString(HbarUnit.Tinybar);
//10 HBAR converted to tinybars
new Hbar(10).toTinybars();
} catch (error) {
console.error(error);
} finally {
if (client) client.close();
}
}
main();
Metadata
Metadata
Assignees
Labels
No labels