Skip to content

A Solidity and Javascript smart contract to store and retrieve generic JSON data in IPFS.

Notifications You must be signed in to change notification settings

anotherFeng/solidity-storage-service

Repository files navigation

Solidity/IPFS Data Access Service

About

A simple reusable data access pattern to tie an Ethereum smart contract to data stored in IPFS. Transactional data can be stored in Ethereum while other data can be externalized to IPFS.

This will allow DApps developers to more easily abstract these layers away.

It will make it faster to build working and testable DApps.

Over time the Ethereum/IPFS implementation details can evolve and all the CRUD DApps we build won't be coupled so tightly to the rapidly changing implementation details.

Usage

TODO://show how the library gets set up

Data Access Service

Creating a record

//Create a javascript object with data you want to save.
let createdRecord = {
    firstName: "Andrew",
    lastName: "McCutchen"
}

//Call the 'create' function
let result = await dataAccessService.create(createdRecord);


//Print results
console.log(result);

/**
* Results
* 
{ id: 1,                                                            # id:        Generated by smart contract
  eventType: 'NEW',                                                 # eventType: NEW
  index: 0,                                                         # index:     The spot in the smart contract index where this record is stored
  ipfsCid: 'zdpuB31DmfwJYHi9FJPoSqLf9fepy6o2qcdk88t9w395b78iT',     # ipfsCid:   Generated by IPFS. 
  owner: '...your address....',                                     # owner:     Saved in smart contract    
  firstName: 'Andrew',                                              # firstName: Stored in IPFS.
  lastName: 'McCutchen'                                             # lastName:  Stored in IPFS.    
}
*/

Reading the record we just created.

//Call the 'read' function
let record = await dataAccessService.read(1);

//Print results
console.log(resultCreatedRecord);


/**
* Results
* 
{ id: 1,                                                            # id:        Generated by smart contract
  index: 0,                                                         # index:     The spot in the smart contract index where this record is stored
  ipfsCid: 'zdpuB31DmfwJYHi9FJPoSqLf9fepy6o2qcdk88t9w395b78iT',     # ipfsCid:   Generated by IPFS. 
  owner: '...your address....',                                     # owner:     Saved in smart contract    
  firstName: 'Andrew',                                              # firstName: Stored in IPFS.
  lastName: 'McCutchen'                                             # lastName:  Stored in IPFS.    
}
*/

Configurable

  • IPFS gateway is configurable. You can have this be a setting chosen by the user in your app.
    • It assumes localhost by default.

Tradeoffs You Make

  • Anything you put in IPFS can theoretically be lost.

    • If you are creating a financial transaction that is dependent on this data, this probably isn't the right pattern to use.
  • You'll probably have to pay for IPFS hosting.

    • Eventually I think this can be done via coin and the DApp itself can be in charge of paying for it. I'm not sure how feasible that is yet.
  • There's some centralization risk in IPFS unless you make an effort (paid, probably) to get others to host the files. This should be mitigated over time.

  • Probably really slow if talking directly to the main Ethereum network.

Includes

  • Solidity smart contract that provides a simple CRUD service to store records.

  • Ethereum will store:

    • The ID that was generated.
    • The IPFS cid where your actual data lives.
    • Which contract owns the record, if applicable.

    This keeps gas costs low.

  • IPFS will contain:

    • A JSON representation of your data.
  • Your actual javascript app (React, Angular, whatever) won't care that it's dealing with a DApp.

    • The js files can also be deployed to IPFS.
  • Makes very simple requests that can be used in your own DApps.

Still very raw, unworking, and probably broken. So far.

About

A Solidity and Javascript smart contract to store and retrieve generic JSON data in IPFS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages