🔑Update Private Key

Script to update the Private Key on an account. Hopefully you do not need to do this very often but if/when you do, good to have in your toolbox.

Note

We encoruage people to try it on a testnet account first just to ensure you are familiar and to use the -test argument [this does everything except try to update it on Hedera side so you can see how it works.]

Reminder: whenever new scripts appear good to run 'npm install' to ensure all prequesite libraries are installed.

Use this script with an extra precaution.

You have to be in possession of the current private key.

N.B. MY_ACCOUNT_ID is the account paying for the transaction. This can be the same account you are changing the key for but it does not have to be.

UPDATE_ACCT= and OLD_KEY= can be left empty and you may supply them as arguments: node updatePrivateKey.js -acc 0.0.222 -pk 302XXXXXXXXXXXXXXXXX3C

The script does not force you to save to a file but this is safest, use -save to output the new key to a file you can use -save to overide the name of the file. If you do not it will ask you for input one last time regarding saving so do not be surprised.

Usage

Edit your .env file (rename .env.example to .env) with the following items:

MY_ACCOUNT_ID=0.0.1111 
MY_PRIVATE_KEY=302.............
##MAIN or TEST environment 
ENVIRONMENT=TEST 
UPDATE_ACCT=0.0.222 
OLD_KEY=302e...........

We recommend to remove the private key from the .env file after use. Extra precaution.

Then, in your Node.js command prompt terminal, you can use

node updatePrivateKey.js [-acc ] [-pk ] [-save []] [-test]

Arguments

-acc - optional - for the account to reset on command line. If not supplied will look for UPDATE_ACCT in .env

-pk - optional - supply private key to reset on command line. If not supplied will look for OLD_KEY in .env

-save XXX - optional - use -save to save the NEW PK to file Supresses console output and specify the file to save to

-test - optional - run script without changing key. Changing keys is scary - this lets you be double sure connfig looks right

Last updated