How to upload data from PC or sensors to blockchain?

0 votes
I am trying to build a blockchain implementation where i can upload data from my home/office PC or sensors to the blockchain and store it. How can i implement it?
Jul 9, 2018 in Blockchain by digger
• 27,630 points
40 views

1 answer to this question.

0 votes

you can do it by writing a chaincode that gets data from PC or sensors and store it in the blockchain..
look at this example which implements something similar to it..


type temperatureSmartContract struct {
}

func (contract *temperatureSmartContract) Init(stub shim.ChaincodeStubInterface) peer.Response {
    fmt.Println("Initialize chaincode if needed")
    return shim.Success(nil)
}

func (contract *temperatureSmartContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
    funcName, params := stub.GetFunctionAndParameters()

    if funcName == "addTemperature" {
        // Store observation into ledger
        stub.PutState("temperature", []byte(params[0]))
    } else if funcName == "getTemperatures" {
        iter, err := stub.GetHistoryForKey("temperature")
        if err != nil {
            shim.Error(fmt.Sprintf("%s", err))
        }

        var result []string
        for iter.HasNext() {
            mod, err := iter.Next()
            if err != nil {
                shim.Error(fmt.Sprintf("%s", err))
            }
            result = append(result, string(mod.Value))
        }
        return shim.Success([]byte(result))
    }
    return shim.Success(nil)
}

answered Jul 9, 2018 by slayer
• 29,050 points

Related Questions In Blockchain

0 votes
1 answer

How to retrieve data from a block to a blockchain?

web3.eth.getTransaction(txHash) will returns transaction details like blockHash, transactionIndex, ...READ MORE

answered Jun 26, 2018 in Blockchain by Perry
• 17,020 points
97 views
+1 vote
1 answer

How to store state data in Ethereum blockchain?

You won't have to overwrite the whole ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,350 points
57 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 27,630 points
67 views
0 votes
1 answer

How to extract Ethereum Blockchain data?

You are using web3.eth.getTransaction(txHash) web3.eth.getTransaction(txHash) will only return info ...READ MORE

answered Jul 29, 2018 in Blockchain by slayer
• 29,050 points
56 views