Get Started

Store your App Data on Blockchain

Introduction

In this guide you will learn how to store your App data on a Blockchain using Back4App.

NOTE: This feature is currently on Alpha Version.

Prerequisites

To complete this tutorial, you will need:

Goal

To store your App’s data on the Blockchain (Ethereum)

Understanding the Blockchain Data Storage

Data storage using blockchain networks offers several advantages, we can highlight some of them:

  • Complete Data Integrity - Data stored on the Blockchain is immutable and indisputable, thanks to cryptographic primitives. As a result, malicious actors cannot forge transactions or other data already made public.
  • 100% Availability - After deploying data on the Blockchain, the network as a whole will always be able to serve clients looking to interact with this data.
  • Privacy - Another essential aspect is that you don’t need to provide a real-world identity to store data on the Blockchain, ensuring privacy when storing the data.

Using Back4App, you can choose which of your App’s classes you want to replicate on a Blockchain of your choice. After selecting a class all its data will be locked/immutable just like blockchain data. Back4App will now store all the upcoming class data on the blockchain.

Step 1 - Replicating a Data on Blockchain

On your App’s dashboard go to Database -> Blockchain.

Choose the Blockchain Network you want to connect with to store your data and check your balance to use this network.

In this Alpha version you can only connect with Back4App private Ethereum Network. You can use this network for development purposes at no cost.

You can now go to Classes in Blockchain section and choose which classes you want to replicate on Blockchain.

Confirm that you want to proceed. This step can take a while.

You can add as many classes as you want to the Blockchain.

In order to see the new Blockchain columns you should refresh your Browser.

Now for the selected classes all the upcoming data will be saved on both Back4App and on the Blockchain Network (Ethereum Private Network).

Step 2 - Checking the replicated Data

After you selected your classes to replicate data on the Blockchain you can now check if its working. Go to one of the selected classes and add some data. In the example below I have a ToDo class with a Title and isDone columns. Before selecting this class to replicatte on Blockchain there were 3 tasks (1,2,3).

Then we replicated the class data on the Blockchain and added more 2 tasks(4,5).

Note that for the ToDo class 2 new columns were created:

  • blockchainStatus - which tells us the status of the replication operation. Its values can be :
    • Sending - It means Back4App have sent the transaction and is waiting for the Blockchain response;
    • Sent - It means the Back4App received a successful response from the Blockchain, and its result is stored on blockchainResult;
    • Failed - The transaction was not successful, and its error message is recorded on blockchainResult;
  • blockchainResult - which tell us the result of the replication operation. An example for the blockchainResult for the Task4 is shown below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
  "type": "Send",
  "input": "{\"Title\":\"Task4\",\"createdAt\":\"2021-09-28T21:33:42.198Z\",\"updatedAt\":\"2021-09-28T21:33:42.198Z\",\"objectId\":\"4dRqXwhZ0Q\",\"__type\":\"Object\",\"className\":\"ToDo\"}",
  "output": {
    "blockHash": "0x606fe02d12d2c32c2041c2c90f89d4687b6472a466ca98d9414d31c7ccceccbd",
    "blockNumber": 252889,
    "contractAddress": null,
    "cumulativeGasUsed": 205180,
    "effectiveGasPrice": "0x3b9aca00",
    "from": "0x150b876cc11ebd4982255bb86b86ac7b1976c775",
    "gasUsed": 205180,
    "logsBloom": "0x00000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000020000000000000080000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000100000000000000000",
    "status": true,
    "to": "0xcd5bc67cb2d23b8004f8ed959b176d445f1fb019",
    "transactionHash": "0xa532e2f89f8383a57bb69a7e41949556b1aebb603e1c302d8e000ddbd0b0611f",
    "transactionIndex": 0,
    "type": "0x0",
    "events": {
      "ClassCreated": {
        "address": "0xcd5bc67Cb2d23B8004f8Ed959b176d445F1fb019",
        "blockNumber": 252889,
        "transactionHash": "0xa532e2f89f8383a57bb69a7e41949556b1aebb603e1c302d8e000ddbd0b0611f",
        "transactionIndex": 0,
        "blockHash": "0x606fe02d12d2c32c2041c2c90f89d4687b6472a466ca98d9414d31c7ccceccbd",
        "logIndex": 0,
        "removed": false,
        "id": "log_fbf279ac",
        "returnValues": {
          "0": "DEU1lLaKScbcQu5Cev31yfZcGQ9q23KfenSLXi0Q",
          "1": "ToDo",
          "_appId": "DEU1lLaKScbcQu5Cev31yfZcGQ9q23KfenSLXi0Q",
          "_className": "ToDo"
        },
        "event": "ClassCreated",
        "signature": "0xfd5b71fb3e543d1d95b62781981b5777c97f2ad93554c5e2af28990d2506b4e0",
        "raw": {
          "data": "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000028444555316c4c614b53636263517535436576333179665a634751397132334b66656e534c586930510000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004546f446f00000000000000000000000000000000000000000000000000000000",
          "topics": [
            "0xfd5b71fb3e543d1d95b62781981b5777c97f2ad93554c5e2af28990d2506b4e0"
          ]
        }
      },
      "ObjectCreated": {
        "address": "0xcd5bc67Cb2d23B8004f8Ed959b176d445F1fb019",
        "blockNumber": 252889,
        "transactionHash": "0xa532e2f89f8383a57bb69a7e41949556b1aebb603e1c302d8e000ddbd0b0611f",
        "transactionIndex": 0,
        "blockHash": "0x606fe02d12d2c32c2041c2c90f89d4687b6472a466ca98d9414d31c7ccceccbd",
        "logIndex": 1,
        "removed": false,
        "id": "log_c078b54b",
        "returnValues": {
          "0": "DEU1lLaKScbcQu5Cev31yfZcGQ9q23KfenSLXi0Q",
          "1": "ToDo",
          "2": "4dRqXwhZ0Q",
          "3": "{\"Title\":\"Task4\",\"createdAt\":\"2021-09-28T21:33:42.198Z\"}",
          "_appId": "DEU1lLaKScbcQu5Cev31yfZcGQ9q23KfenSLXi0Q",
          "_className": "ToDo",
          "_objectId": "4dRqXwhZ0Q",
          "_objectJSON": "{\"Title\":\"Task4\",\"createdAt\":\"2021-09-28T21:33:42.198Z\"}"
        },
        "event": "ObjectCreated",
        "signature": "0x41f3752dbeef66b4f3cbc3e77aa71e7ce2ff5996a6008fefc36cf033e27f4761",
        "raw": {
          "data": "0x000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000028444555316c4c614b53636263517535436576333179665a634751397132334b66656e534c586930510000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004546f446f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a346452715877685a30510000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000387b225469746c65223a225461736b34222c22637265617465644174223a22323032312d30392d32385432313a33333a34322e3139385a227d0000000000000000",
          "topics": [
            "0x41f3752dbeef66b4f3cbc3e77aa71e7ce2ff5996a6008fefc36cf033e27f4761"
          ]
        }
      }
    }
  }
}

Step 3 - Understanding Blockchain Response

In the type field, we specify the Ethereum Smart Contract operation to execute. Its values can assume:

Send

For sending the value described on the input field. In this case, the Output will list the Ethereum Network transaction response with all the saved events;

Get

For consulting the Ethereum Network to confirm if an object is already saved. In case of any problem with the replication operation, Back4App will confirm if the object has been saved and store the Blockchain response on the blockchainResponse field.

Error

That means the operation was not successful. In this case the Outputvalue will list the error message;

Conclusion

In this guide you could learn more about how to store your App Data on a Blockchain network of your choice.

Common questions

What is Blockchain data storage?

Blockchain storage saves data in a decentralized network as an alternative to centralized cloud storage. This approach has characteristics that differ from traditional centralized data storage, like immutability, 100% availability, and anonymity.

How much App data can you store on a Blockchain?

There is no limit to how much data you can store on a Blockchain. There is only a limit that defines the size of a block which changes depending on the Blockchain protocol.

Can we remove App data from a Blockchain?

No. Once you save data on a blockchain, the data will be immutable, which means you cannot update or delete it.

Is there a way to check the transaction on a Blockchain?

We are currently working on this improvement. In upcoming versions, you will check the transaction using a block-explorer.

How many transactions are you creating for each object?

At this moment, we are creating a single transaction per object.

Do I have to pay for using this feature?

At this Alpha version, you do not have to pay.

Which Blockchain is available for App Data storage?

We’ve released only a private Ethereum Network on this first version, where we created a Smart Contract for data storage. This Smart Contract will be open-sourced soon.