Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@christroutner
Last active February 22, 2019 22:25
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 christroutner/38f5357345650d201faf7be53ce303c8 to your computer and use it in GitHub Desktop.
Save christroutner/38f5357345650d201faf7be53ce303c8 to your computer and use it in GitHub Desktop.
SLP TX Details

The purpose of this gist is to explore different formats for a new endpoint on rest.bitcoin.com with regard to SLP transaction details.

The examples below are based on this testnet TXID: 57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b9457822d446

The above transaction was generated by the SLP SDK examples. An initial quantity of 1234 tokens was produced. Here is the token details. The TX above is sending 12.3 tokens from that initial quantity to testnet address bchtest:qqukhrjh45xttrfsu2vj7gsy0v7zqdm65cd8t4me9y.

The objective/scope of this new rest endpoint is to take a TXID as input, and produce the following convenient metadata as output:

  • sentFrom
  • sentTo
  • quantity
  • symbol
  • tokenId

This is a convenient endpoint that existed in Wormhole, but does not exist in SLP. The initial investigations are captured in this GitHub Issue

Current limitations of this code:

  • It does not capture the quantity of input tokens on the vin
  • There is no token information for the change address (last tx output). This is probably expected, but worth noting.

Option 1

The first option is to combine the output of getRawTransaction() and append any token details. The JSON below does exactly that. When looking at the data below, focus on the following properties:

  • tokenInfo object is attached to the root object (at the bottom)
  • tokens property is attached to each vout element, representing the number of tokens transfered in that output.

This output is the most simplistic. It requires the least processing. It is verbose, but that has both pros and cons. The output below can be reproduced using the ct-token-transfer branch of the rest.bitcoin.com repository, in this code chunk

{
  "hex": "020000000349bbe39feacb819f890223b39096781a64b6c9f5e8d9308f1518dca35415e761020000006a4730440220409e79fec552f01203f41d3d621ae3db89c720af261c8268ce5f0453de009f5d022001e7ffefeba7b0716d32ea55cb6ace267b6ee9cbcc8a017bb9c3b6acf7889418412103c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585ffffffff49bbe39feacb819f890223b39096781a64b6c9f5e8d9308f1518dca35415e761010000006b483045022100a743bee56c99bd103be48a78fa4c7342100815d9d2448dbe6e1d338c3a13b241022066728b5279fc22eef5cd019582ff34771e29175835fc98aa3168a1548fd78ac8412103c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585ffffffff49bbe39feacb819f890223b39096781a64b6c9f5e8d9308f1518dca35415e761030000006b483045022100821473902eec5f1ce7d43b1ba7f9ec453bfe8b8dfc3de3e0723c883ab109922f02206162960e80618531fab2c16aee260fddd7979bab62471c8686af7de75f8732ec412103c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585ffffffff040000000000000000406a04534c500001010453454e44207ac7f4bb50b019fe0f5c81e3fc13fc0720e130282ea460768cafb49785eb2796080000000049504f80080000001c71e6428022020000000000001976a914396b8e57ad0cb58d30e2992f22047b3c20377aa688ac22020000000000001976a914aa099b067337dc20993bbfdb5c4f3c6867ba2c5b88ac5b8a9800000000001976a914aa099b067337dc20993bbfdb5c4f3c6867ba2c5b88ac00000000",
  "txid": "57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b9457822d446",
  "hash": "57b3082a2bf269b3d6f40fee7fb9c664e8256a88ca5ee2697c05b9457822d446",
  "size": 628,
  "version": 2,
  "locktime": 0,
  "vin": [
    {
      "txid": "61e71554a3dc18158f30d9e8f5c9b6641a789690b32302899f81cbea9fe3bb49",
      "vout": 2,
      "scriptSig": {
        "asm": "30440220409e79fec552f01203f41d3d621ae3db89c720af261c8268ce5f0453de009f5d022001e7ffefeba7b0716d32ea55cb6ace267b6ee9cbcc8a017bb9c3b6acf7889418[ALL|FORKID] 03c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585",
        "hex": "4730440220409e79fec552f01203f41d3d621ae3db89c720af261c8268ce5f0453de009f5d022001e7ffefeba7b0716d32ea55cb6ace267b6ee9cbcc8a017bb9c3b6acf7889418412103c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585"
      },
      "sequence": 4294967295
    },
    {
      "txid": "61e71554a3dc18158f30d9e8f5c9b6641a789690b32302899f81cbea9fe3bb49",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100a743bee56c99bd103be48a78fa4c7342100815d9d2448dbe6e1d338c3a13b241022066728b5279fc22eef5cd019582ff34771e29175835fc98aa3168a1548fd78ac8[ALL|FORKID] 03c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585",
        "hex": "483045022100a743bee56c99bd103be48a78fa4c7342100815d9d2448dbe6e1d338c3a13b241022066728b5279fc22eef5cd019582ff34771e29175835fc98aa3168a1548fd78ac8412103c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585"
      },
      "sequence": 4294967295
    },
    {
      "txid": "61e71554a3dc18158f30d9e8f5c9b6641a789690b32302899f81cbea9fe3bb49",
      "vout": 3,
      "scriptSig": {
        "asm": "3045022100821473902eec5f1ce7d43b1ba7f9ec453bfe8b8dfc3de3e0723c883ab109922f02206162960e80618531fab2c16aee260fddd7979bab62471c8686af7de75f8732ec[ALL|FORKID] 03c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585",
        "hex": "483045022100821473902eec5f1ce7d43b1ba7f9ec453bfe8b8dfc3de3e0723c883ab109922f02206162960e80618531fab2c16aee260fddd7979bab62471c8686af7de75f8732ec412103c87f0ec048a0771bdb60533d45cac88c6974afeb055a65edd663c2f947335585"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_RETURN 5262419 1 1145980243 7ac7f4bb50b019fe0f5c81e3fc13fc0720e130282ea460768cafb49785eb2796 0000000049504f80 0000001c71e64280",
        "hex": "6a04534c500001010453454e44207ac7f4bb50b019fe0f5c81e3fc13fc0720e130282ea460768cafb49785eb2796080000000049504f80080000001c71e64280",
        "type": "nulldata"
      },
      "tokens": 0
    },
    {
      "value": 0.00000546,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 396b8e57ad0cb58d30e2992f22047b3c20377aa6 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914396b8e57ad0cb58d30e2992f22047b3c20377aa688ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "bchtest:qqukhrjh45xttrfsu2vj7gsy0v7zqdm65cd8t4me9y"
        ]
      },
      "tokens": 12.3
    },
    {
      "value": 0.00000546,
      "n": 2,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 aa099b067337dc20993bbfdb5c4f3c6867ba2c5b OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914aa099b067337dc20993bbfdb5c4f3c6867ba2c5b88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "bchtest:qz4qnxcxwvmacgye8wlakhz0835x0w3vtvaga95c09"
        ]
      },
      "tokens": 1221.7
    },
    {
      "value": 0.09996891,
      "n": 3,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 aa099b067337dc20993bbfdb5c4f3c6867ba2c5b OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914aa099b067337dc20993bbfdb5c4f3c6867ba2c5b88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "bchtest:qz4qnxcxwvmacgye8wlakhz0835x0w3vtvaga95c09"
        ]
      }
    }
  ],
  "blockhash": "000000000000ce978accc64a6bb567acf0c653c202309a0f8e220149bf0c6968",
  "confirmations": 1,
  "time": 1550855104,
  "blocktime": 1550855104,
  "tokenInfo": {
    "id": "7ac7f4bb50b019fe0f5c81e3fc13fc0720e130282ea460768cafb49785eb2796",
    "timestamp": "2019-02-15 03:13",
    "symbol": "SLPSDK",
    "name": "SLP SDK example using BITBOX",
    "documentUri": "developer.bitcoin.com",
    "documentHash": "",
    "decimals": 8,
    "initialTokenQty": 1234
  }
}

Option 2

A second option is to return a more concise output like the below example. This also shines a light on some of the current limitations I'm bumping up against:

  • Not sure how to decode the inputs. The slpjs library has a parseSlpOutputScript(buffer) for parsing outputs, but does not seem to have a similar function for inputs.

The code to produce this output is in the ct-token-transfer2 branch of the rest.bitcoin.com repository, in this code chunk

{
  "inputs": [
    {
      "address": "unknown",
      "tokensIn": "unknown"
    },
    {
      "address": "unknown",
      "tokensIn": "unknown"
    },
    {
      "address": "unknown",
      "tokensIn": "unknown"
    }
  ],
  "outputs": [
    {
      "address": "unknown",
      "tokensOut": "unknown"
    },
    {
      "address": [
        "bchtest:qqukhrjh45xttrfsu2vj7gsy0v7zqdm65cd8t4me9y"
      ],
      "tokensOut": 12.3
    },
    {
      "address": [
        "bchtest:qz4qnxcxwvmacgye8wlakhz0835x0w3vtvaga95c09"
      ],
      "tokensOut": 1221.7
    },
    {
      "address": [
        "bchtest:qz4qnxcxwvmacgye8wlakhz0835x0w3vtvaga95c09"
      ],
      "tokensOut": "unknown"
    }
  ],
  "symbol": "SLPSDK",
  "tokenId": "7ac7f4bb50b019fe0f5c81e3fc13fc0720e130282ea460768cafb49785eb2796",
  "decimals": 8
}

@jcramer
Copy link

jcramer commented Feb 22, 2019

Chris, I think maybe we want to use SLPJS for this. I added a method as a starting point to align with your "Option 1" above.

simpleledger/slpjs@5da34c8

I haven't had a chance to test it out, running short on time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment