How to get the Redeem Script for a P2SH Address From Private Key with PHP

By | May 26, 2020

Just a quick piece of code, that is using Bitwasp library to mare redeem script from private key


<?php
require __DIR__ . "/vendor/autoload.php";

use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory;
use BitWasp\Bitcoin\Script\ScriptFactory;

// Private key for address
$wifkey='privatekeycomeshere';

// Initializing Private Key Class
$privKeyFactory = new PrivateKeyFactory();

// Getting private key from the one stored in WIF format
$key = $privKeyFactory->fromWif($wifkey);

$redeemScript = ScriptFactory::scriptPubKey()->p2wkh($key->getPubKeyHash());

print_r($redeemScript);

?>

Leave a Reply

Your email address will not be published. Required fields are marked *