Verify Evidence
To verify an asset evidence from Track API, we have 3 ways to interact with the Blockchain network.
As an example, we will use the asset from the following image:
For all verification methods, the assetHash
, timestamp
, and networkId
fields will be used. Additionally, for methods 2 and 3, the smartContract
field will also be used. All of them are highlighted in red in the image.
Method 1: Interact with the TrustOS API
This is the simplest and most direct method once the integration with TrustOS is done, and the one we recommend for most cases.
Essentially, you need to call the following endpoint of the Cert API:
For more detailed information on how to make this call, you can refer to the technical documentation of the endpoint.
Method 2: Interacting with the corresponding block explorer
This method depends on the existence of a block explorer that allows the query of the Blockchain where the evidence has been registered.
To do this, you need the address of the Smart Contract where the evidence has been registered (field smartContract
) and use the block explorer corresponding to the network that appears in the networkId
field.
In this link the Smart Contract is shown in the block explorer.
Next, you need to access the contract tab and check the available functions.
The function to call is getEvidence
and the parameters to pass are the assetHash
and the timestamp
of the evidence you want to verify. Finally, run the function with the Query button and it will show the result, which matches the hash
field of the evidence.
Method 3: Directly querying the Blockchain
In Blockchain networks, all information is pseudopublic since anyone can read it. To interact directly with the Blockchain, we will use what is known as the JSON-RPC API.
This is a communication protocol that facilitates interaction with Blockchain networks based on the Ethereum client.
To make this protocol work, you need the so-called JSON-RPC-ENDPOINT. This is the “gateway” to interact with the Blockchain and is nothing more than an open connection to a node running the Ethereum-based Blockchain client that we need.
Thanks to this communication method, you can query information such as the Ethereum client implemented by the desired Blockchain, or even the networkId of the Blockchain. An example of a call for the latter would be:
If we use a Polygon’s JSON-RPC-ENDPOINT, the response will be 137.
Now, for the specific case of verifying an evidence registered using Track API, the call that needs to be made is called eth_call, which executes a call to the Blockchain without creating a transaction. Since it is a read method, there will be no gas cost or network fees involved.
The call would look like this:
The fields to fill in are as follows:
- JSON-RPC-ENDPOINT
- SMART_CONTRACT: Address of the Smart Contract where the evidence has been registered (field
smartContract
). - INFO: Hash of the function signature and the encoded parameters
assetHash
andtimestamp
.
To encode the parameters, you can use the following online tool, taking into account that the function of the Smart Contract to be called is:
Once all the parameters are correctly encoded, the call looks like this:
The response to this call, if done correctly, can be in 2 ways.
-
Evidence not found
The hexadecimal value
0x09cea733
corresponds to the error returned by the Smart Contract when the evidence is not found.The parameters entered do not match the records stored in the Blockchain.
-
Evidence found
The result, encoded, is the hash associated with that assetHash at that specific timestamp.
To decode it, you can use the following online tool.
As you can see, the decoded parameter matches the hash of the evidence, ensuring the immutability of the information.