2

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?

1

Unlike bitcoin, ethereum eoa address does not distinguish between mainnet and testnet.

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.