bitcoin-php icon indicating copy to clipboard operation
bitcoin-php copied to clipboard

Create transaction example

Open tcolonel opened this issue 1 year ago • 0 comments

Hello.

Could you write an example of creating a transaction, signing it, and obtaining a transaction hash that can be sent further - having:

  • only with private key
  • only private key in WIF format

So I don't know nothing about prev tx and so on. I have only private key in diff formats which I get from:

private function generateWallet()
{
    $oPrivateKeyFactory = new PrivateKeyFactory();
    $oRandom = new Random();
    $this->sPrivateKey = $oPrivateKeyFactory->generateCompressed($oRandom);
    $this->sPrivateKeyWif = $this->sPrivateKey->toWif();
    $this->sPublicKey = $this->sPrivateKey->getPublicKey();
    $sPublicKeyHash = $this->sPublicKey->getPubKeyHash();
    $oAddress = new PayToPubKeyHashAddress($sPublicKeyHash);
    $this->sAddress = $oAddress->getAddress($this->oNetwork);
    $oSegwitAddress = new SegwitAddress(WitnessProgram::v0($sPublicKeyHash));
    $this->sSegwitAddress = $oSegwitAddress->getAddress();
}

I read these links and many others, but they didn't help me:

  • https://github.com/Bit-Wasp/bitcoin-php/issues/895
  • https://github.com/Bit-Wasp/bitcoin-php/issues/861
  • https://github.com/Bit-Wasp/bitcoin-php/issues/849
  • https://github.com/Bit-Wasp/bitcoin-php/issues/835
  • https://github.com/Bit-Wasp/bitcoin-php/issues/790
  • https://github.com/Bit-Wasp/bitcoin-php/issues/780
  • https://stackoverflow.com/questions/73182011/trying-to-generate-wallet-addresses-from-master-public-key-using-the-bitwasp-bit
  • https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/doc/tx/003_create_txout.php

I need a simple solution: received the keys, the address, created a transaction, signed, sent (I know that I a not empty balance).

Thanks.

tcolonel avatar Jan 22 '24 20:01 tcolonel