Skip to content

Audit Trail

Introduction to STRATO Audit Trail

The Audit Trail allows a user to view a historical record of the smart contract states. State changes that come from transactions made on the smart contract are stored in a postgres database as they occur. This means that for each state update, the contract itself is updated as well as a contract history table in the postgres database. As a result of this feature, the postgres database can be queried for the contract’s history.

Enabling Audit Trail

By default, the audit trail and contract history will default to false, meaning that no audit trail or contract history will be provided. To enable the audit trail feature, you have two options:

  • Through the API, by passing an additional metadata to the POST endpoint when uploading the contract, like this:
curl -X POST "https://<your_ip_address>/bloc/v2.2/users/<your_username>/<your_user_address>/contract" -H "accept: application/json;charset=utf-8" -H "Content-Type: application/json;charset=utf-8" -d "{\"password\":\"<yourPassword>\",\"contract\":\"<your_contract_name>\",\"src\":\"<your_contract>\",\"metadata\":{\"history\":\"<your_contract_name>\"}}"

If you are uploading a list and need to enable the contract history, this is done by adding a metadata to the request body. The history field is a comma-separated list of contract names, e.g. "history":"SimpleStorage,Vehicle,VehicleManager". This allows you to turn history on for contracts that you aren't creating directly, e.g. Vehicles or Tickets created by a manager or a factory:

curl -X POST "https://<your_ip_address>/bloc/v2.2/users/<your_username>/<your_user_address>/uploadList" -H "accept: application/json;charset=utf-8" -H "Content-Type: application/json;charset=utf-8" -d "{\"contracts\":[{\"args\":[{\"args\":{\"balance\":10,\"accountType\":\"Checking\"},\"contractName\":\"AccountsContract\",\"metadata\":{\"history\":\"AccountsContract, SimpleStorage, PermissionsManager\"}}],\"resolve\":true,\"password\":\"SecretPassword\"}" 

Querying For The Audit Trail

Below are examples of how to query for the audit trail on the main chain, on a private chain or on multiple chains:

Main Chain

curl -X GET "https://stratodemo.blockapps.net/cirrus/search/[email protected]<contractName>?chainId=eq.0&address=eq.<address>" -H "accept: */*" -H "Range-Unit: items"

The result will be a JSON response that looks something like this:

{   
    "chainId": "",
    "blockNumber": "1020392",
    "transactionHash": "03849392",
    "sender": "0x369...",
    "state": {
        "storedData": "39483"
    }
}
To see the current state of the contract, the command is similar, but without the history term included:

curl -X GET "https://stratodemo.blockapps.net/cirrus/search/<contractName>?chainId=eq.0&address=eq.<address>" -H "accept: */*" -H "Range-Unit: items"

Private Chain

curl -X GET "https://stratodemo.blockapps.net/cirrus/search/<contractName>?chainId=<chainId>.&address=eq.<address>" -H "accept: */*" -H "Range-Unit: items"

The result will be a JSON response that looks something like this:

{   
    "chainId": "53",
    "blockNumber": "1020392",
    "transactionHash": "03849392",
    "sender": "0x369...",
    "state": {
        "storedData": "39483"
    },
    "chainId": "53",
    "blockNumber": "1020392",
    "transactionHash": "93482929",
    "sender": "0x123...",
    "state": {
        "storedData": "872382"
    }
}

Multiple Chains

Finally, for multiple chains, the curl command will be something like:

curl -X GET "https://stratodemo.blockapps.net/cirrus/search/<contractName>?chainId=in.<chainID1>,<chainID2>"

And the JSON will look something like the following:

{   
    "chainId": "123",
    "blockNumber": "1020392",
    "transactionHash": "03849392",
    "sender": "0x369...",
    "state": {
        "storedData": "39483"
    },
    "chainId": "234",
    "blockNumber": "1020392",
    "transactionHash": "93482929",
    "sender": "0x123...",
    "state": {
        "storedData": "872382"
    }
}

Example Scenario

  • Upload SimpleStorage.sol, enable “history” (if SMD, check “history” box in Upload Contract modal, if API, add ?history=true to URL query param), and call setData with a value of 8
  • Call setData with a value of 10
  • You can see this result on the SMD dashboard by navigating to Contracts -> SimpleStorage -> Query Builder. Here, you will see a history table showing the initial state and updated state by block number. Or, you could also see the result by querying the Cirrus endpoint: cirrus/search/contractName