24
loading...
This website collects cookies to deliver better user experience
pragma solidity >=0.4.21 <0.6.0;
contract myContract{
string data;
function set(string memory data){
data=data;
}
function get() public view returns(string memory){
return data;
}
}
NOTE: If the variable was string public data then solidity by-default gives the getter function with the same name as that of the variable, i.e., in this case data() which would simply return that same variable.
const myContract= artifacts.require('myContract');
module.exports = function(deployer) {
deployer.deploy(myContract);
};
truffle migrate
npm install --save ipfs-http-client
const create = require('ipfs-http-client')
const ipfs = create('https://ipfs.infura.io:5001')
const run = async ()=>{
const data= await ipfs.add(“Hello World”)
const resultCID= file[‘path’]
console.log(resultCID);
} // You could put a file buffer as well or anything
run();
Content Identifiers (CID): A content identifier, or CID, is a label used to point to material in IPFS. It doesn’t indicate where the content is stored, but it forms a kind of address based on the content itself. CIDs are formed with the hash of the data itself, hence any change in data would mean different CID allocation for the data. IPFS uses an advanced data structure called Merkle Directed Acyclic Graphs (DAG) in which every node carries the payload and is given an identifier. Read more here .
1. const contract= myContract.deployed()
2. setData= contract.set(<paste the CID that was earlier received>)
// This set() command will consume gas as it's changing state
3. getData= contract.get()
4. getData
Join Coinmonks Telegram Channel and learn about crypto trading and investing