1

I am trying to construct a header of a transaction. So my question is - what is the difference between ref_block_num and ref_block_prefix in a transaction header and how to retrieve it? is there a way to get these information from v1/chain/get_info ?

Many thanks for your help in advance :)

1 Answer 1

2
  ref_block_num     ///< specifies a block num in the last 2^16 blocks.
  ref_block_prefix  ///< specifies the lower 32 bits of the blockid at get_ref_blocknum

  ...

  /**
  * @return the absolute block number given the relative ref_block_num
  */
  block_num_type get_ref_blocknum( block_num_type head_blocknum )const {
     return ((head_blocknum/0xffff)*0xffff) + head_blocknum%0xffff;
  }

https://github.com/EOSIO/eos/blob/e87d245da0e458edc66139c3ca59f71861bcc1dd/libraries/chain/include/eosio/chain/transaction.hpp#L32


Dan elaborates | Source.:

ref_block_num / ref_block_prefix -> this transaction can only in blockchains where the highest block_num%0xff has a blockid that contains ref_block_prefix. Stated another way, this says the transaction can only be included in forks that build off of the reference block.

Taken together the transaction is only valid for the specified period of time and can be declared invalid if it isn't included in a block by the time the last irreversible block time is equal to the expiration.

EOSIO uses this information to prevent replay attacks on transactions.


From docs

The ref_block_num and ref_block_prefix here are provided as a result of /v1/chain/get_block of the last_irreversible_block. The last_irreversible_block can be found by calling /v1/chain/get_info. You also need to use /v1/wallet/sign_transaction to get the right signature.

REQUEST:
---------------------
POST /v1/chain/get_info HTTP/1.0
Host: jungle2.cryptolions.io
content-length: 0
Accept: */*
Connection: close


---------------------
RESPONSE:
---------------------
{
  "server_version": "ea08cfd3",
  "chain_id": "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473",
  "head_block_num": 3324665,
  This guy
  "last_irreversible_block_num": 3324336,
  Right there ^
  "last_irreversible_block_id": "0032b9b007cf91079677cb22a523fce2402ed92334958f64a124222cb8b06ecc",
  "head_block_id": "0032baf9d0d72cfa104884c8cd5ca031a3c65d8ff7e373052b3f0c967375c6c3",
  "head_block_time": "2018-12-13T03:19:50.000",
  "head_block_producer": "jungleswedem",
  "virtual_block_cpu_limit": 200000000,
  "virtual_block_net_limit": 1048576000,
  "block_cpu_limit": 199920,
  "block_net_limit": 1048576,
  "server_version_string": "v1.5.0"
}

cleos get block 1:

{
  "timestamp": "2018-03-02T12:00:00.000",
  "producer": "",
  "confirmed": 1,
  "previous": "0000000000000000000000000000000000000000000000000000000000000000",
  "transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000",
  "action_mroot": "0000000000000000000000000000000000000000000000000000000000000000",
  "schedule_version": 0,
  "new_producers": null,
  "header_extensions": [],
  "producer_signature": "SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne",
  "transactions": [],
  "block_extensions": [],
  "id": "0000000130d70e94e0022fd2fa035cabb9e542c34ea27f572ac90b5a7aa3d891",
  "block_num": 1,
  Other guy
  "ref_block_prefix": 3526296288
  Is right here ^, this took a long time to put together
}

Full transaction.

  • req POST /v1/chain/get_info HTTP/1.0
  • req POST /v1/wallet/get_public_keys HTTP/1.0
  • req POST /v1/chain/get_required_keys HTTP/1.0 (get ref_block_num & ref_block_prefix here)
  • req POST /v1/wallet/sign_transaction HTTP/1.0
  • req POST /v1/chain/push_transaction HTTP/1.0

REQUEST:

POST /v1/chain/get_info HTTP/1.0
Host: jungle2.cryptolions.io
content-length: 0
Accept: */*
Connection: close



RESPONSE:

{
  "server_version": "ea08cfd3",
  "chain_id": "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473",
  "head_block_num": 3324665,
  "last_irreversible_block_num": 3324336,
  "last_irreversible_block_id": "0032b9b007cf91079677cb22a523fce2402ed92334958f64a124222cb8b06ecc",
  "head_block_id": "0032baf9d0d72cfa104884c8cd5ca031a3c65d8ff7e373052b3f0c967375c6c3",
  "head_block_time": "2018-12-13T03:19:50.000",
  "head_block_producer": "jungleswedem",
  "virtual_block_cpu_limit": 200000000,
  "virtual_block_net_limit": 1048576000,
  "block_cpu_limit": 199920,
  "block_net_limit": 1048576,
  "server_version_string": "v1.5.0"
}

REQUEST:

POST /v1/wallet/get_public_keys HTTP/1.0
Host: /home/natanaelprudhomme/eosio-wallet/keosd.sock:
content-length: 0
Accept: */*
Connection: close



RESPONSE:

[
  "EOS5QaqpbQtA98cBbYwhK49wdm2Qdhf7x4hYHb9WkvrSLUNxWm995",
  "EOS5WgXLzLwTXKeRGQV3BSn1saGtT4bkA8jbfLc4L1uTPb9sN6UAw",
  "EOS63zNBrWgKWp2P9pqL5vvKWRdUtJX9tznamw8MkxVSeMGgWYVD5",
  "EOS67wLi78ak2fqffpvGedNqRTEcEeNTZhKBxM3n3cgjBwGerEZgv",
  "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  "EOS7dsJbPAhRCjTwPB28nithDunNZ1oCMTNRC8g31Y3oahx3w62z8",
  "EOS7jEjKydV7Ve7KbkLNbC6WYpTEqCy7KU8asuWJNu1e3qsGYmic2",
  "EOS85wQgYFL2GnU368P3PVDShMpcqcXTVd1JpLBNTMt5jMEBUBUhv",
  "EOS8DEzBSBrYTJu5GdnsN5oJm5QHPT4zqgLGcPuZuc8Xgfib31Xux"
]

REQUEST:

POST /v1/chain/get_required_keys HTTP/1.0
Host: jungle2.cryptolions.io
content-length: 1213
Accept: */*
Connection: close

{
  "transaction": {
    "expiration": "2018-12-13T03:20:20",
    "ref_block_num": 47536,
    "ref_block_prefix": 583759766,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
        "account": "eosio",
        "name": "updateauth",
        "authorization": [{
            "actor": "eosezchatnat",
            "permission": "owner"
          }
        ],
        "data": "90cdcca6a1af305500000000a8ed32320000000080ab26a7010000000100039205fa96bd143deddb53d53e810d7e5292ddeb592a9633c64d963d68dbbc72e201000000"
      }
    ],
    "transaction_extensions": []
  },
  "available_keys": [
    "EOS5QaqpbQtA98cBbYwhK49wdm2Qdhf7x4hYHb9WkvrSLUNxWm995",
    "EOS5WgXLzLwTXKeRGQV3BSn1saGtT4bkA8jbfLc4L1uTPb9sN6UAw",
    "EOS63zNBrWgKWp2P9pqL5vvKWRdUtJX9tznamw8MkxVSeMGgWYVD5",
    "EOS67wLi78ak2fqffpvGedNqRTEcEeNTZhKBxM3n3cgjBwGerEZgv",
    "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
    "EOS7dsJbPAhRCjTwPB28nithDunNZ1oCMTNRC8g31Y3oahx3w62z8",
    "EOS7jEjKydV7Ve7KbkLNbC6WYpTEqCy7KU8asuWJNu1e3qsGYmic2",
    "EOS85wQgYFL2GnU368P3PVDShMpcqcXTVd1JpLBNTMt5jMEBUBUhv",
    "EOS8DEzBSBrYTJu5GdnsN5oJm5QHPT4zqgLGcPuZuc8Xgfib31Xux"
  ]
}

RESPONSE:

{
  "required_keys": [
    "EOS5QaqpbQtA98cBbYwhK49wdm2Qdhf7x4hYHb9WkvrSLUNxWm995"
  ]
}

REQUEST:

POST /v1/wallet/sign_transaction HTTP/1.0
Host: /home/natanaelprudhomme/eosio-wallet/keosd.sock:
content-length: 807
Accept: */*
Connection: close

[{
    "expiration": "2018-12-13T03:20:20",
    "ref_block_num": 47536,
    "ref_block_prefix": 583759766,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
        "account": "eosio",
        "name": "updateauth",
        "authorization": [{
            "actor": "eosezchatnat",
            "permission": "owner"
          }
        ],
        "data": "90cdcca6a1af305500000000a8ed32320000000080ab26a7010000000100039205fa96bd143deddb53d53e810d7e5292ddeb592a9633c64d963d68dbbc72e201000000"
      }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
  },[
    "EOS5QaqpbQtA98cBbYwhK49wdm2Qdhf7x4hYHb9WkvrSLUNxWm995"
  ],
  "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473"
]

RESPONSE:

{
  "expiration": "2018-12-13T03:20:20",
  "ref_block_num": 47536,
  "ref_block_prefix": 583759766,
  "max_net_usage_words": 0,
  "max_cpu_usage_ms": 0,
  "delay_sec": 0,
  "context_free_actions": [],
  "actions": [{
      "account": "eosio",
      "name": "updateauth",
      "authorization": [{
          "actor": "eosezchatnat",
          "permission": "owner"
        }
      ],
      "data": "90cdcca6a1af305500000000a8ed32320000000080ab26a7010000000100039205fa96bd143deddb53d53e810d7e5292ddeb592a9633c64d963d68dbbc72e201000000"
    }
  ],
  "transaction_extensions": [],
  "signatures": [
    "SIG_K1_KA3jZ6oTMeUUHnpAsXCh9Z6JLHhQavgp9k1pK8W8o6nAmTcJUipPYSP1Fm64WWsw6jn1UcwBSmCoXfkWuPsqqos6DP3AbD"
  ],
  "context_free_data": []
}

REQUEST:

POST /v1/chain/push_transaction HTTP/1.0
Host: jungle2.cryptolions.io
content-length: 446
Accept: */*
Connection: close

{
  "signatures": [
    "SIG_K1_KA3jZ6oTMeUUHnpAsXCh9Z6JLHhQavgp9k1pK8W8o6nAmTcJUipPYSP1Fm64WWsw6jn1UcwBSmCoXfkWuPsqqos6DP3AbD"
  ],
  "compression": "none",
  "packed_context_free_data": "",
  "packed_trx": "f4cf115cb0b99677cb2200000000010000000000ea30550040cbdaa86c52d50190cdcca6a1af30550000000080ab26a74390cdcca6a1af305500000000a8ed32320000000080ab26a7010000000100039205fa96bd143deddb53d53e810d7e5292ddeb592a9633c64d963d68dbbc72e20100000000"
}

RESPONSE:

{
  "transaction_id": "3e7a7805c17e0621822c63dc2a90f59713acd1ee2a8b4390385183375d3617f0",
  "processed": {
    "id": "3e7a7805c17e0621822c63dc2a90f59713acd1ee2a8b4390385183375d3617f0",
    "block_num": 3324669,
    "block_time": "2018-12-13T03:19:52.000",
    "producer_block_id": null,
    "receipt": {
      "status": "executed",
      "cpu_usage_us": 512,
      "net_usage_words": 20
    },
    "elapsed": 512,
    "net_usage": 160,
    "scheduled": false,
    "action_traces": [{
        "receipt": {
          "receiver": "eosio",
          "act_digest": "5d7da6b5aff4f83a95c691965507d34b05c79723bf8d3cb84b918a1a89404039",
          "global_sequence": 21018317,
          "recv_sequence": 4666459,
          "auth_sequence": [[
              "eosezchatnat",
              294
            ]
          ],
          "code_sequence": 2,
          "abi_sequence": 3
        },
        "act": {
          "account": "eosio",
          "name": "updateauth",
          "authorization": [{
              "actor": "eosezchatnat",
              "permission": "owner"
            }
          ],
          "data": {
            "account": "eosezchatnat",
            "permission": "active",
            "parent": "owner",
            "auth": {
              "threshold": 1,
              "keys": [{
                  "key": "EOS7wYVzWFWFu8AViGr8XZvb3npfPz9btujCLQ5d7PZtsbHeorgw3",
                  "weight": 1
                }
              ],
              "accounts": [],
              "waits": []
            }
          },
          "hex_data": "90cdcca6a1af305500000000a8ed32320000000080ab26a7010000000100039205fa96bd143deddb53d53e810d7e5292ddeb592a9633c64d963d68dbbc72e201000000"
        },
        "context_free": false,
        "elapsed": 87,
        "console": "",
        "trx_id": "3e7a7805c17e0621822c63dc2a90f59713acd1ee2a8b4390385183375d3617f0",
        "block_num": 3324669,
        "block_time": "2018-12-13T03:19:52.000",
        "producer_block_id": null,
        "account_ram_deltas": [{
            "account": "eosezchatnat",
            "delta": 0
          }
        ],
        "except": null,
        "inline_traces": []
      }
    ],
    "except": null
  }
}
2
  • Thank you mate! This was exactly what I was looking for
    – jinjineos
    Dec 14, 2018 at 2:51
  • Very glad to hear that. Took me a hot minute to put that guy together.
    – Nat
    Dec 14, 2018 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.