0

Whilst going through the documentation for using JSON RPC, 1 of the parameters hasn't been explained. What is the purpose of id? Is it specific to the type of RPC curl request being made?

For e.g.

id=67

curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}'

id=64

curl -X POST --data '{"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":64}'

However it doesn't look like there is a standard id for particular call either. So I was left confused about the purpose behind it.

1

It's a standard JSON-RPC field.

According to the specification

id

An identifier established by the Client that MUST contain a String, Number, or NULL value if included. If it is not included it is assumed to be a notification. The value SHOULD normally not be Null 1 and Numbers SHOULD NOT contain fractional parts [2]

The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.

(1) The use of Null as a value for the id member in a Request object is discouraged, because this specification uses a value of Null for Responses with an unknown id. Also, because JSON-RPC 1.0 uses an id value of Null for Notifications this could cause confusion in handling.

(2) Fractional parts may be problematic, since many decimal fractions cannot be represented exactly as binary fractions.

You're not guaranteed to get your answers back in the order you asked for them; the id is to help you sort that out.

| improve this answer | |
  • Thanks. So basically it like the sequence number used in TCP connection message payload to now which request is this response corresponding to. – Chaitanya Bapat Jul 9 '18 at 16:11

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