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
• 26,740 points
1,120 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,370 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 27, 2018 in Blockchain by Perry
• 17,100 points
3,985 views
+1 vote
2 answers
0 votes
0 answers
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,470 views
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
• 26,740 points
1,037 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 30, 2018 in Blockchain by slayer
• 29,370 points
1,727 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP