My code to Generate ETH Address and other Address like BCH looks like this
function generateEthAddress($xpub, $index){
$Bitcoin = new Bitcoin();
$Bitcoin->setNetwork($this->isMainNet() ? new MultiCoinNetwork('ETH') : new MultiCoinNetwork('ETH', 'test'));
$network = $Bitcoin->getNetwork();
$factory = new HierarchicalKeyFactory();
$root = $factory->fromExtended($xpub, $network)
->withoutPrivateKey()
->derivePath($index);
$pubkey = $root->getPublicKey();
$hdaddress = new PayToPubKeyHashAddress($pubkey->getPubKeyHash());
$array = array("address" => $hdaddress->getAddress());
return json_encode($array);
}
My code to Generate ETH WIF and other WIF like BCH looks like this
function generateEthPrivateKey($mnemonic, $index){
$Bitcoin = new Bitcoin();
$Bitcoin->setNetwork($this->isMainNet() ? new MultiCoinNetwork('ETH') : new MultiCoinNetwork('ETH', 'test'));
$network = $Bitcoin->getNetwork();
$path = $this->getPath("ETH");
$seedGenerator = new Bip39SeedGenerator();
$seed = $seedGenerator->getSeed($mnemonic);
$factory = new HierarchicalKeyFactory();
$root = $factory->fromEntropy($seed);
$hdwallet = $root->derivePath($path."/".$index)->getPrivateKey();
$array = array("key" => $hdwallet->toWif($network));
return json_encode($array);
}
but this is not giving me promising result please can you refactor my code to let me me get the real way of how it will work?
this Exactly works when i use with BTC and LTC using
$Bitcoin->setNetwork($this->isMainNet() ? NetworkFactory::bitcoin() : NetworkFactory::bitcoinTestnet());
and
$Bitcoin->setNetwork($this->isMainNet() ? NetworkFactory::litecoin() : NetworkFactory::litecoinTestnet());
thanks.
i have really tried but i didn't want to rewrite another code just give me how this lib can solve my question with my approach above thanks.
My code to Generate ETH Address and other Address like BCH looks like this
My code to Generate ETH WIF and other WIF like BCH looks like this
but this is not giving me promising result please can you refactor my code to let me me get the real way of how it will work?
this Exactly works when i use with BTC and LTC using
thanks.
i have really tried but i didn't want to rewrite another code just give me how this lib can solve my question with my approach above thanks.