I want to generate an address without a key so that it can serve as a burn address - an address to which tokens can be sent and never retrieved from. How do I generate one?
You can use PolkadotJS' keyring submodule:
const { encodeAddress } = require('@polkadot/keyring');
const zero = '0x' + '00'.repeat(32);
const output = encodeAddress(zero, 2);
console.log(output.toString());
This outputs: CaKWz5omakTK7ovp4m3koXrHyHb7NG3Nt7GENHbviByZpKp
which is a Kusama address (due to the 2
in encodeAddress
above) that can never be unlocked - there is no private key for the public key 0x0
.
Alternatively, encodeAddress(new Uint8Array(32))
also works - u8a is initialized with 0s, and for random addresses, you can use encodeAddress(randomAsU8a())
.