Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using coinparams not working fully for me #6

Open
HighBreedTech opened this issue Feb 2, 2021 · 1 comment
Open

Using coinparams not working fully for me #6

HighBreedTech opened this issue Feb 2, 2021 · 1 comment

Comments

@HighBreedTech
Copy link
Contributor

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.

@HighBreedTech
Copy link
Contributor Author

@dan-da help me with little refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant