I just started Ethereum. I found how to generate an address by using JavaScript like below. I need an address for testnet. I'm using Ropsten testnet. In bitcoin, I can generate from pubkey to both mainnet address and testnet address. Does Ethereum have the same rule?
var bip39 = require('bip39');
var hdkey = require('ethereumjs-wallet/hdkey')
var mnemonic = 'xxx xxx xxx...';
var password = '';
var masterseed = bip39.mnemonicToSeed(mnemonic, password);
var hdnode = hdkey.fromMasterSeed(masterseed);
var getKeyPair = function(hdnode){
return {
"address" : hdnode.getWallet().getAddressString(),
"private" : hdnode.getWallet().getPrivateKeyString(),
"public" : hdnode.getWallet().getPublicKeyString(),
}
}
// cointype=60=eth
// m / purpose' / coin_type' / account' / change / address_index
console.log(getKeyPair(hdnode.derivePath("m/44'/60'/0'/0/0"))) // { address: '0xbc0c53d89b2fe10d1d140665bd94b3d926f4a790', private: 'xxx', public: 'xxx' }
Update 1
Seems the address format of mainnet and testnet are same.
There is no way to verify if an address belongs to a particular network - they are all valid for every Ethereum network.
Are addresses between different networks (testnet) interchangeable?