简体   繁体   中英

Storing Data on Blockchain

I am working on a POC where I have to store some data eg ID of an object, price, owner and things like that. Is it possible to store such things on Blockchain using smart contracts. And if not what are the ways to use Blockchain to achieve it. (I did some research, and people are using Blockchain in SCM industry. They must have stored these kind of datas).

Consider following tutorial from Hyperledger Fabric " Getting Started " pages.

Basically you implement requested logic on by leveraging chaincodes , you will have to implement following golang interface:

// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
    // Init is called during Instantiate transaction after the chaincode container
    // has been established for the first time, allowing the chaincode to
    // initialize its internal data
    Init(stub ChaincodeStubInterface) pb.Response

    // Invoke is called to update or query the ledger in a proposal transaction.
    // Updated state variables are not committed to the ledger until the
    // transaction is committed.
    Invoke(stub ChaincodeStubInterface) pb.Response
}

For example something similar to this:

type myStoreChaincode struct {
}

func (cc *myStoreChaincode) Init(stub ChaincodeStubInterface) pb.Response {
    return shim.Success(nil)
}

func (cc *myStoreChaincode) Invoke(stub ChaincodeStubInterface) pb.Response {
    action, params = stub.GetFunctionAndParameters()
    if action == "storeItem" {
        cc.StoreItem(stub, params)
    }

    // Handle here other cases and possible parameters combinations
    return shim.Success(nil)
}

func (cc *myStoreChaincode) StoreItem(stub ChaincodeStubInterface, params []string) {
      // Store item on ledger, where params[0] is a key and params[1] actual value
      stub.PutState(params[0], params[1])
}

This is only a simplified version, while for more complex you can follow " Writing Your Application " tutorial.

Yes, you can store information about assets in Blockchain implemented in Hyperledger Fabric (current version is 1.0). Information about assets is updated via chaincode (go language based transactions). It's fairly easy to start experimenting with this by using the HyperLedger Composer Playground . HyperLedger Composer, which uses HyperLedger Fabric V1 as it's operating foundation, simplifies the process of writing, and especially prototyping, new Blockchain applications.

Composer uses a modelling language to define the characteristics of your network (what member types, asset types, events, and transactions define the core network). It has a robust Access Control Language to specify precisely who can access which assets and which transactions. It has a simplified query language which automatically invokes the ACL when queries are executed (meaning that even if you were to ask for information you shouldn't see, you still can't see it) and finally, allows you to write all of your code in a single language - Javascript at the moment - including the chaincode for smart transactions.

Yes if you use Ethereum smart contracts you can define your contract and store it with transactions.

https://www.ethereum.org/greeter

Note that if you don't encrypt the data stored in the contract it will be accessible by everyone.

Yes, you can store what you want using contracts. And of course, you have to encrypt your records. However, in my opinion this isn't the issue.

You define your contract and deploy it to your peers. Your contract should define how to store transactions. Also, it should define how to verify them.

您可以通过在合同中使用适当的数据结构来存储数据,然后进行生成散列的事务,您需要随时保存以供访问

Yes, it is possible to store data in smart contract, you can use truffle framework to create a smart contract and a UI too. You can create a new smart contract everytime you store something on that and also store the address of previous contract which you created. It makes easy to track also.

Don't store data in smart contracts. That's entirely impractical and expensive. What you'd need is IPFS. IPFS is a peer-to-peer protocol that allows for immutable and decentralized file sharing and data storage. With IPFS, in combination with a blockchain, like Ethereum, for instance, data is stored via IPFS and then associated hash can be tied to a smart contract. Anyone with the hash can call that data.

It is certainly possible to encode this type of data in a blockchain. For a detailed look at this process consider visiting these repositories on Github. These files represent MIT's and The Learning Lab's efforts in adding earned certificates to the blockchain. The certs involve much of the data you're looking to encode broken down to multiple components of the process: creating, viewing, verifying and storing the certificates.
What you're trying to do is pretty nascent. As a result it can be detailed and complicated. The MIT implementation is good as they offer up Docker packages that take care of a good deal of the details offering an opportunity to understand the process more holistically. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM