Steps to check if the application is working fine :
- Install ganache to use as test blockchain network.
- Change ganache port to 8545 for Metamask to catch or create a new network on Metamask. (Optional)
- Import two accounts from Ganache to MetaMask by copying the private key to MetaMask.
- Clone the repo and install packages
git clone https://github.com/shivammutrejarug/react_ipfs_ethereum.git
cd react_ipfs_ethereum/client
npm install .
- If you haven't made changes as suggested in step 2, change the port to 7545 i.e the default ganache port in truffle-config.js
- Deploy the contract and run tests.
truffle migrate \\this will deploy the contract on the blockchain.
truffle test \\run test cases.
If all test cases pass, the code is good.
Steps to replicate :
- Follow first 4 steps from the previous section.
- Remove verifier.sol from the contracts folder.
- Copy verificationTest.js from the test folder to a tmp location.
- Comment lines 2 and 6 in the 2_deploy_contracts.js file indside migrations folder.
- Go to the client folder and run
npm run start
. This should automatically open the browser. If not, open the browser and go tohttp://localhost:3000
. - There will be two forms on the view. Fill the second form with the asked details and press submit. This will take you to the MetaMask page and you'll have to confirm the transcation.
- Once the transaction is successfull, the page will reaload and you'll see your file on the view.
- Now that we have the NFT on the blockchain. Let's transfer this to another user. Use the first form on the view and fill the owner's (your) address and the receiver's address. Submit.
- This will take you to the MetaMask page and you'll have to confirm the transcation. Once the transaction is successfull, you can be sure that the NFT was shared. If you want to check, you can go open the truffle console and fetch to the deployed contract and call the ownerOf function with the argument as the tokenId.
let instance = await User.deployed()
instance.contract.methods.totalSupply().call()
instance.contract.methods.ownerOf(2).call()
- Now that we have transferred the file, we need to prove to the receiver that we own the NFT and that the owner has shared the NFT with him.
Steps 11 through 18 can be achieved by running the file test_bash.sh
-
Make sure you are in the
react_ipfs_ethereum
directory. Now move to get_hash directorycd get_hash
. Runzokrates compile -i create_hash.zok
. -
Run
node getIpfsHashParams.js <your-ipfs-hash>
. This will give you the command you need to run to generate the witness with zokrates compatible arguments. -
Run the command from the previous step and copy the output.
-
Now, move down the directory
cd ..
toreact_ipfs_ethereum
and runzokrates compile -i root.zok
. -
Run
zokrates setup
. This will provide us with the proving key and the verification key which will be used in the generating the proof. -
Run
zokrates export-verifier
. This will provide us with theverifier.sol
file which will be deployed on-chain later. -
Run
node getParams.js <your-private-key> <random-private-key> <your-ipfs-hash> <first-of-two-copied-strings> <second-of-two-copied-strings>
. -
You'll receive the command to run the witness. Run that command. Now uncomment lines commented in step 4.
-
Run
zokrates generate-proof
. This will give a file with name proof.json which will be used to fetch the arguments forverifyTx
function inverifier.sol
-
Copy the verifier.sol to contracts folder and copy verificationTest.js from tmp folder to test.
-
Run
truffle migrate --network development
. -
Run
truffle test
. If all test cases pass, the verifier can be sure that the proof is genuine.
See it in action - https://youtu.be/oFQHVCS8D1A