This project is a decentralized property ownership product using ERC-721 Tokens and zkSNARKS for zero knowledge proof of ownership.
This project was built using the following framework versions:
- Truffle v5.1.14-nodeLTS.0 (core: 5.1.13)
- Ganache CLI v6.9.1 (ganache-core: 2.10.2)
- OpenZeppelin (openzeppelin-solidity) v2.5.1
- Solidity v0.5.16 (solc-js)
- Node v12.18.1
- Web3.js v1.2.1
- Truffle Assertions v0.9.2
To run the test suite for the smart contracts:
- Clone this repo
- Change into the project directory
cd Udacity-Blockchain-Capstone/
- Ensure you already have npm v6.14.5 and node v12.18.1 installed.
- Install dependenceis
npm i
- Install Ganache CLI
npm i -g ganache-cli
- Install Truffle
npm i -g truffle@nodeLTS
- Check truffle version by running
truffle version
. - Change into the eth-contracts directory
cd eth-contracts
- Create an empty .secret file
touch .secret
- Compile the contracts
truffle compile
- In one terminal window, start ganache-cli
ganache-cli
- In a separate terminal window, run the smart contract specs via
truffle test
After following the above process, you should see all the tests passing as they are on Travis CI.
This project uses ZoKrates for implementing zkSNARKS. To run ZoKrates in a Docker Container, run the following command:
docker run -v $(pwd)/zokrates/code:/home/zokrates/code -ti zokrates/zokrates:0.4.6 /bin/bash
In the running container terminal execute the following commands to compile the proof code, setup and export the verifier contract.
cd code/square
~/zokrates compile -i ./code/zokrates/code/square/
~/zokrates setup
~/zokrates export-verifier
Now generate 10 different unique proofs ready for the NFT minting process:
~/zokrates compute-witness -a 1 1
~/zokrates generate-proof
mv proof.json proof1.json
~/zokrates compute-witness -a 2 4
~/zokrates generate-proof
mv proof.json proof2.json
~/zokrates compute-witness -a 3 9
~/zokrates generate-proof
mv proof.json proof3.json
~/zokrates compute-witness -a 4 16
~/zokrates generate-proof
mv proof.json proof4.json
~/zokrates compute-witness -a 5 25
~/zokrates generate-proof
mv proof.json proof5.json
~/zokrates compute-witness -a 6 36
~/zokrates generate-proof
mv proof.json proof6.json
~/zokrates compute-witness -a 7 49
~/zokrates generate-proof
mv proof.json proof7.json
~/zokrates compute-witness -a 8 64
~/zokrates generate-proof
mv proof.json proof8.json
~/zokrates compute-witness -a 9 81
~/zokrates generate-proof
mv proof.json proof9.json
~/zokrates compute-witness -a 10 100
~/zokrates generate-proof
mv proof.json proof10.json
Use an Infura project to deploy to Rinkeby. Take a look in truffle-config file to see the Rinkby network configuration.
To migrate contracts to the Rinkeby network run:
truffle migrate --network rinkeby
The Verifier and SolnSquareVerifier Contracts are already deployed to Rinkeby at the following addresses:
- Verifier Contract on Rinkeby 0x32F13a3Cd59dDC8148deE0CD1B8fACbcA5D93794
- SolnSquareVerifier Contract on Rinkeby 0x70797237915074795Adc107F3751710c6eE58e4f
Below are the truffle migration logs for the contract deployments:
Deploying 'Verifier'
--------------------
> transaction hash: 0x35528c5267a4838e9d290aa6a2d8e45085f286843725e6b23956f67a1faf765c
> Blocks: 0 Seconds: 5
> contract address: 0x32F13a3Cd59dDC8148deE0CD1B8fACbcA5D93794
> block number: 6703297
> block timestamp: 1592704929
> account: 0x3aD2405264636d19F2869F4580c68391744EBCA1
> balance: 18.32067154
> gas used: 1013474 (0xf76e2)
> gas price: 10 gwei
> value sent: 0 ETH
> total cost: 0.01013474 ETH
Deploying 'SolnSquareVerifier'
------------------------------
> transaction hash: 0x4b0d8d29ac704365283f0c61cb9474463797a61430c7f1ac3ed3be39c64a85d1
> Blocks: 2 Seconds: 21
> contract address: 0x70797237915074795Adc107F3751710c6eE58e4f
> block number: 6703299
> block timestamp: 1592704959
> account: 0x3aD2405264636d19F2869F4580c68391744EBCA1
> balance: 18.28387767
> gas used: 3679387 (0x38249b)
> gas price: 10 gwei
> value sent: 0 ETH
> total cost: 0.03679387 ETH
Below are links to the contract ABIs:
Steps to mint tokens via MEW
- Open MEW homepage.
- Select Access via MetaMask
- Make sure you are logged into MetaMask and connected to the Rinkeby network.
- Click Access My Wallet button
- Click Interact with Contract link
- Paste in the deployed contract address (e.g. 0x70797237915074795Adc107F3751710c6eE58e4f) and the SolnSquareVerifier Contract ABI.
- Select the mint function (NOT the mintNFT function!) so that you can mint 10 tokens to your own address on the Rinkby network without having to submit a proof. This is OK for the testing of this contract for this case.
- Paste your address from MetaMask into the To (address) field and the TokenID (unit256) field set to any number. Try 99 first for testing.
- Confirm the transaction with MetaMask
- View the transaction on Ethersacn.
- Continue to mint TokenIds 1 to 10.
The deployed and minted KHPT Tokens can be viewed via the Etherscan Token Tracker here. This shows the total supply of tokens available and who owns them.
For example the TokenId 99 just minted above is viewable.
Once the contract is deployed and tokens are minted, its possible to display them on via an OpenSea storefront. Steps to do this are as follows:
- Open the get listed page on OpenSea.
- Enter the deployed SolnSquareVerifier contract address.
- This will magically generate a storefront like this one for the KH PROPERTY TOKEN.
Once your storefront is created you can begin to auction your assets.
- Ensure that you are logged into MetaMask with the account that you used to mint the tokens earlier.
- Select each of the tokens one by one and click the Sell button.
- Set the price and other parameters as you see fit. For this example, I set all token prices to 0.1 ETH.
- A number of transactions will need to be performed the first time around then after that only a signed confirmation is required.
Once tokens are available for auction on OpenSea they can be purchased!
- Switch accounts in MetaMask to a different account to the current owner of all the tokens. Make sure that this account has some Ether!
- Select a property / token and now you should be asked if you want to buy it!
- Click Buy button, sign the transaction, wait for confirmation and now you are the new owner of this property / token.
- You can verify this transfer of ownership via the Etherscan Token Tracker
The trading activity for the KHPT tokens can be viewed in the OpenSea Activity Log for the KH_PROPERTY_TOKEN Stream.
The 5 purchased / sold / transfered tokens are:
The 5 unpurchased (still owned by the original contract owner) tokens are:
- KH_PROPERTY_TOKEN #6
- KH_PROPERTY_TOKEN #7
- KH_PROPERTY_TOKEN #8
- KH_PROPERTY_TOKEN #9
- KH_PROPERTY_TOKEN #10
If you experience with bugs or need further improvement, please create a new issue under Issues.
Pull requests are very welcome. Before submitting a pull request, please make sure that your changes are well tested. Pull requests without tests will not be accepted. In this project we currently use Truffle Tests (Mocha JS / Chai JS).
This Decentralized Property Ownership Product application was developed as part of the Blockchain Nanodegree with Udacity and Darren Jensen.
This Decentralized Property Ownership Product application is released under AGPL
This application is part of a project assignment and is most definitely not suitable for Production use! :)