1

I am new to Solidity, Web3, and Ethereum. I am trying to build a web application through which users can upload a file to IPFS, then store the IPFS hash in the blockchain. I am using the React truffle box and the value is being stored via the SimpleStorage contract that's included with the box.

So essentially, the ideal scenario would be: User A uploads the file to IPFS and its hash is stored in the blockchain. User B can then access the file by typing the transaction hash and getting its storage value to check whether it's authentic or not.

The problem is that in order for User B to be able to check the file's authenticity, they need to have the transaction hash. Is there a way for a function to return the hash on function call? I can get it manually through Ganache, but that's just impractical.

The blockchain is very nice because it gives you the ability to permanently store data within it, but is there a way to check that data?

Thank you.

1 Answer 1

1

with that simpleStorage contract, you are storing a value in a smart contract on the blockchain. So User B need only the address of that deployed smart contract and then he could call the method get() from that contract to get the stored value.

contract SimpleStorage {
  uint storedData;

  function set(uint x) public {
    storedData = x;
  }

  function get() public view returns (uint) {
    return storedData;
  }
}

with web3js you can deploy a contract and get its address with this code

// When the data is already set as an option to the contract itself

myContract.options.data = '0x12345...';

myContract.deploy({
    arguments: [<not needed in your contract>]
})
.send({
    from: '0x1234567890123456789012345678901234567891',
    gas: 1500000,
    gasPrice: '30000000000000'
})
.then((newContractInstance) => {
    console.log(newContractInstance.options.address) // instance with the new contract address
});

https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html

more infos: truffle save the address of the deployed contract, the abi, meta data and bytecode.... in the build Folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.