Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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