Clarification about private key format in README.md
Closed this issue · 1 comments
codewiz commented
From https://github.com/ava-labs/avalanche-smart-contract-quickstart#deploy-to-fuji-or-mainnet :
Deploy to Fuji or Mainnet
You need to add your private key to the accounts field in hardhat.config.js.
How do I extract a private key in the expected format? Private keys for the Fuji net are in the form PrivateKey-[a-zA-Z0-9]+
, but hardhat expects hex-encoded Ethereum keys (0x[0-9A-F]+
)
cgcardona commented
Our private keys are encoded as cb58. You can use AvalancheJS to convert cb58 to the hex string that you want. Here's a script
import {
BinTools,
Buffer
} from "avalanche";
const main = async (): Promise<any> => {
const bintools: BinTools = BinTools.getInstance()
const privKey: string = "PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
const decoded: Buffer = bintools.cb58Decode(privKey.split('-')[1])
console.log(`0x${decoded.toString('hex')}`)
// 0x56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027
const cb58: string = bintools.cb58Encode(decoded)
console.log(`PrivateKey-${cb58}`)
// PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN
}
main()