-1

How do I retrieve the hashcode of a bitcoin transaction from any service. E.g.

https[:]//blockchain[dot]info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e

or

https[:]//blockchain[dot]info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e?adv_view=1

or

https[:]//btc[dot]blockr[dot]io/tx/info/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e

Chris Pickford
  • 8,642
  • 5
  • 42
  • 73
Ngan
  • 15
  • 3
  • Welcome to Stack Overflow! I've edited the formatting of your question to improve readability which might increase the possibility of receiving helpful answers. – Chris Pickford Aug 17 '16 at 09:32

1 Answers1

0

Manually read it from the string

For example, in "https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e" just read the last 64 characters. Tx-Codes are always 64 characters long.

Regular Expressions

If you have multiple services/websites from which you want to read the Tx-Id, you can save the position where the Tx-Id starts in the string and then read 64 characters from there. Since you did not say which programming language you want to use, I'll show an example in C++:

#include <iostream>
#include <string>
#include <vector>
#include <regex>


using namespace std;

struct PositionInString
{
     PositionInString(string h, unsigned int p) : host(h), position(p) {}

     string host;
     unsigned int position;
};

int main()
{
     vector<PositionInString> positions;
     positions.push_back(PositionInString("blockchain.info", 27));
     positions.push_back(PositionInString("btc.blockr.io", 30));

     while(true)
     {
          string url;
          cout << "Enter url: ";
          cin >> url;

          regex reg_ex("([a-z0-9|-]+\\.)*[a-z0-9|-]+\\.[a-z]+");
          smatch match;
          string extract;

          if (regex_search(url, match, reg_ex))
          {
               extract = match[0];
          }
          else
          {
               cout << "Could not extract." << endl;
               continue;
          }



          bool found = false;
          for(auto& v : positions)
          {
               if(v.host.compare(extract) == 0)
               {
                    cout << "Tx-Id: " << url.substr(v.position, 64) << endl;
                    found = true;
                    break;
               }
          }

          if(found == false)
               cout << "Unknown host \"" << extract <<  "\"" << endl;
     }


     return 0;
}

Output:

Enter url: https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e
Tx-Id: a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e
Bobface
  • 2,782
  • 4
  • 24
  • 61
  • thank @Bobface but i want function can use for every service with it own doman i dont need to collect domain into function – Ngan Aug 24 '16 at 04:49
  • Then use a regular expression which searchs for a 64 character string. – Bobface Aug 24 '16 at 08:46