Created
January 29, 2022 07:24
-
-
Save dimitardanailov/556291746284550354c325eb798eae10 to your computer and use it in GitHub Desktop.
Create an Account on Algorand + re-generate the address from public key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import algosdk from 'algosdk' | |
const createAddress = () => { | |
const account = algosdk.generateAccount() | |
const mn = algosdk.secretKeyToMnemonic(account.sk) | |
console.log('Account Mnemonic:', mn) | |
console.log('account', account) | |
const {publicKey, checksum} = algosdk.decodeAddress(account.addr) | |
const buffer = Buffer.from(publicKey) | |
const pubKeyBase64: string = buffer.toString('base64') | |
const pubKeyArray: Uint8Array = Buffer.from(pubKeyBase64, 'base64') | |
const address = algosdk.encodeAddress(pubKeyArray) | |
console.log('account.addr === address', account.addr === address) | |
console.log('account.addr', account.addr) | |
console.log('address', address) | |
console.log('public key', publicKey) | |
console.log('checksum', checksum) | |
return { | |
address: account.addr, | |
publicKey: publicKey, | |
} | |
} | |
export default createAddress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment