shivam kumar
shivam kumar

Reputation: 21

Invalid Private length Issue

 throw new _BadKeyError.default(`invalid private key length: ${data.length} bytes`);

getting this error while setting up test environment

const { Client } = require("@hashgraph/sdk");
require("dotenv").config();

async function main() {

    //Grab your Hedera testnet account ID and private key from your .env file
    const myAccountId = process.env.MY_ACCOUNT_ID;
    const myPrivateKey = process.env.MY_PRIVATE_KEY;

    // If we weren't able to grab it, we should throw a new error
    if (myAccountId == null ||
        myPrivateKey == null ) {
        throw new Error("Environment variables myAccountId and myPrivateKey must be present");
    }

    // Create our connection to the Hedera network
    // The Hedera JS SDK makes this really easy!
    const client = Client.forTestnet();

    client.setOperator(myAccountId, myPrivateKey);
    console.log('success');
    client.close();
}
main();

above code i ran and got the error.kindly someone check

Upvotes: 2

Views: 103

Answers (1)

Abi
Abi

Reputation: 493

The error message given points me to think your private key may be off. Double-check your .env file and ensure you have entered in your private key correctly.

Upvotes: 2

Related Questions