Skip to content

Instantly share code, notes, and snippets.

@sniper7kills
Created February 15, 2017 03:29
Show Gist options
  • Save sniper7kills/3a3e2911564144cabb84ccaee3273757 to your computer and use it in GitHub Desktop.
Save sniper7kills/3a3e2911564144cabb84ccaee3273757 to your computer and use it in GitHub Desktop.
<?php
$ec = Bitcoin::getEcAdapter();
$key = PrivateKeyFactory::fromWif('YOUR_WIF');
$outpoint = new OutPoint(Buffer::hex('YOUR_TRANSACTION', 32), 0);
$scriptPubKey = ScriptFactory::scriptPubKey()->payToPubKeyHash($key->getPublicKey());
$value = 0;
$txOut = new TransactionOutput($value, $scriptPubKey);
$op = new Opcodes();
$destination = new WitnessProgram(0, $key->getPubKeyHash());
$sh = ScriptFactory::sequence([Opcodes::OP_RETURN, Buffer::hex('WHAT YOU WANT TO SEND']);
$p2sh = new \BitWasp\Bitcoin\Script\P2shScript($destination->getScript(), $op);
$tx = TransactionFactory::build()
->spendOutPoint($outpoint)
->payToAddress($txref['value'], AddressFactory::fromString($key->getPublicKey()->getAddress()->getAddress()))
->output(0, $sh)
->get();
$signed = new \BitWasp\Bitcoin\Transaction\Factory\Signer($tx, $ec);
$signed->sign(0, $key, $txOut);
$ss = $signed->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment