Skip to main content

Transactions with Data Script Outputs

Using script outputs to store data on the blockchain. Examples of data that can be handled by this type of request are IPFS links, hashes, or any information that can be represented as a String. This feature extends the use of blockchain to functionalities based on some data stored on it, such as transaction traceability. Basically, a data output must be added to a transaction along with other common UTXOs. It is also possible to create a transaction with solely a data output.

info

There can be up to 25 outputs of this type per transaction.

Parameters

  • x-wallet-id: Wallet identifier.
  • inputs (optional): Array of JSON objects.
    • hash: Hash of the transaction being spent in the input.
    • index: Index of the output being spent in the input.
  • outputs: Array of JSON objects
    • type: Fixed key of type String and value "data"
    • data: String data to be stored on the blockchain. It is limited to 150 characters.

Request

curl -X POST -H "X-Wallet-Id: gitbook-wallet" -H "Content-type: application/json" \
--data '{"outputs": [{"type": "data", "data": "https://ipfs.io/ipfs/QmTzWz3zm9rB5UNJvzPa2gfj9d82TzNz8nrMtSSBJgEant/"}]}' \
http://localhost:8000/wallet/send-tx

Response

Below is the JSON returned by the request. It can be viewed in Hathor Explorer via this link. Note that the transaction has the data output, i. e., there was no need to create a custom token. Instead, only one string was added to the blockchain.

{
"success":true,
"inputs":[
{
"hash":"009bafac22b4225860fdb5467e181bd91c54972f89ef0129391cc04f42811422",
"index":1,
"data":{
"type":"Buffer",
"data":[+]
},
"tx_id":"009bafac22b4225860fdb5467e181bd91c54972f89ef0129391cc04f42811422"
}
],
"outputs":[
{
"value":78,
"script":{
"type":"Buffer",
"data":[+]
},
"tokenData":0,
"decodedScript":null,
"token_data":0
},
{
"value":1,
"script":{
"type":"Buffer",
"data":[+]
},
"tokenData":0,
"decodedScript":null,
"token_data":0
}
],
"version":1,
"weight":8.000001,
"nonce":46,
"timestamp":1651924663,
"parents":[
"00e7516e0c00433822e0517f83cb71248168647d04cd758a75b49a6cd3b9d6ee",
"00314c0d6ee3cf6701100253fb954bec105053a1418cb723f0d42c32a12491c4"
],
"tokens":[],
"hash":"00ea4f2860664f3e97ce251d55523a0796bccd6218f0a1a9def241f3a9d1514b",
"_dataToSignCache":null
}

It is also possible to create a transaction by mixing data outputs and common UTXOs.

Request

curl -X POST -H "X-Wallet-Id: gitbook-wallet" -H "Content-type: application/json" \
--data '{"outputs": [{"type": "data", "data": "https://ipfs.io/ipfs/QmTzWz3zm9rB5UNJvzPa2gfj9d82TzNz8nrMtSSBJgEant/"}, {"address": "WaK3xqn67TmgiaVGfSrsJt2owjbVbgBNRj", "value": 1, "token": "00425511ca7a0f04886040e4d8dd4012bb3466d2d8b890ff0285750025794948"}]}' \
http://localhost:8000/wallet/send-tx

Response

{
"success":true,
"inputs":[
{
"hash":"00cdbccb0c2f50612e33e0fff6e07f903b3f828b199e22662df2fa8e029f21ee",
"index":1,
"data":{
"type":"Buffer",
"data":[+]
},
"tx_id":"00cdbccb0c2f50612e33e0fff6e07f903b3f828b199e22662df2fa8e029f21ee"
},
{
"hash":"00cdbccb0c2f50612e33e0fff6e07f903b3f828b199e22662df2fa8e029f21ee",
"index":2,
"data":{
"type":"Buffer",
"data":[+]
},
"tx_id":"00cdbccb0c2f50612e33e0fff6e07f903b3f828b199e22662df2fa8e029f21ee"
}
],
"outputs":[
{
"value":1,
"script":{
"type":"Buffer",
"data":[+]
},
"tokenData":0,
"decodedScript":null,
"token_data":0
},
{
"value":53,
"script":{
"type":"Buffer",
"data":[+]
},
"tokenData":0,
"decodedScript":null,
"token_data":0
},
{
"value":1,
"script":{
"type":"Buffer",
"data":[+]
},
"tokenData":1,
"decodedScript":null,
"token_data":1
}
],
"version":1,
"weight":8.000001,
"nonce":79,
"timestamp":1652453377,
"parents":[
"007a01c0e157f97afc6a5c95b38f67350f3caeba5ccd64dca50b8271d92bc421",
"00cdbccb0c2f50612e33e0fff6e07f903b3f828b199e22662df2fa8e029f21ee"
],
"tokens":[
"00425511ca7a0f04886040e4d8dd4012bb3466d2d8b890ff0285750025794948"
],
"hash":"00733efee7c7e9551b0bf440c5f95bf7dbcf3aec814f49a14a593385c0ab9df9",
"_dataToSignCache":null
}