Search code examples
node.jscachingethereumsolidity

Caching data if connection is down


I've got a server that I'm relaying every action that I want to do with a smart contract, but let's say the server can't connect to the smart contract (the connection is down). How would I cache such actions and execute them once the connection is up.


Solution

  • Interaction with smart contract (SC) has 2 types:

    • Call to update status (write data)
    • Call to view function (read data)

    In order to do the write data, we need:

    • SC address
    • Method name
    • Data option
    • Parameters
    • Sender

    So we can organize into a JS object

    {
     'address': 0x..,
     'method': 'transfer',
     'dataOption': { 
        'from': '0x...',
        'value': 100 (wei)
      },
     'params': ['param1', 'param2', ...]
    }
    

    Then you can determine where should we use it depends on the use cases:

    • Can be store at server using: SQL, MongoDB, json file...
    • Can be store inside the front-end using: storage