Skip to content

Instantly share code, notes, and snippets.

@scriptzteam
Forked from JburkeRSAC/bitcoin_decode.php
Created May 24, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptzteam/5c7494704c041f27ff3e1359ead676eb to your computer and use it in GitHub Desktop.
Save scriptzteam/5c7494704c041f27ff3e1359ead676eb to your computer and use it in GitHub Desktop.
decode bitcoin OP_RETURN
<?php
$transaction_id = $argv[1];
$url = "https://blockchain.info/tx/$transaction_id?show_adv=true&format=json";
$result = file_get_contents($url);
$resultJSON = json_decode($result, true);
function hex2str($hex) {
$str = '';
for($i=0;$i<strlen($hex);$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
return $str;
}
//zero false positives that there is a hidden message
function fetchZeroValMSG($resultJSON){
$outgoing_transaction = $resultJSON['out'];
#print_r($outgoing_transaction);
foreach($outgoing_transaction AS $this_transaction){
#print_r($this_transaction);
if($this_transaction['value'] == 0){
$code = $this_transaction['script'];
echo hex2str($code)."\n";
}
}
}
function fetchPotentialMSG($resultJSON){
$outgoing_transaction = $resultJSON['out'];
foreach($outgoing_transaction AS $this_transaction){
$code = $this_transaction['script'];
$str2 = substr($code, 6);
$code = $str2;
unset($str2);
$str3 = substr($code, 0, -4);
$code = hex2str($str3);
unset($str3);
echo $code;
}
}
fetchPotentialMSG($resultJSON);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment