The purpose of this repository is to demonstrate how to develop upgradeable smart contracts.
Truffle v4.1.12 Node v8.11.3
Once Truffle and Node are installed:
- Navigate to project dir via terminal
- run
truffle develop
-Starts a development blockchain which will allow you to "migrate" the smart contracts onto. - run
compile
-Compiles all the smart contracts into their respective "ABIs." - run
migrate
-Migrate the contracts onto the development server. - In a separate terminal tab/window navigate to the project dir and run
npm run start
-This will start a development server which you can access viahttp://localhost:3000
in your browser - Setup MetaMask (below)
MetaMask is an Ethereum wallet Chrome extension, which makes it easy to process transactions in browser. To interact with this application, this extension needs to be installed and setup properly. Out of the box it is setup to connect to the main Ethereum network, but we want it to interact with our local development blockchain.
- Install the MetaMask Chrome Extension
- Once installed, open up MetaMask and locate Main Ethereum Network at the top. Click on this to open up other network options.
- At the bottom click on Custom RPC.
- Under New RPC URL input the address:
http://localhost:9545
then save.(This is the port that the development chain should be running on) - At this point MetaMask should connect to your development blockchain if it's running. Once MetaMask is setup on the private network, the front-end can send and recieve data from the blockchain.
- Logout of MetaMask, then click Import using account seed phrase.
- Find the seed phrase given from the development blockchain and use it to setup a new account. (This seed phrase is normally printed in the console when the development blockchain started.)
- Now you have access to test funds from your newly created account on the development blockchain.
The workings of this proxy would not be possible without the knowledge gained from the following article: How to write upgradable smart contracts in solidity!
This repo was designed to take the idea of upgradeable smart-contracts one step further and add interface support so that large contracts can be split to meet gas constraints.
Below you will find a visual of how all of the contracts interact together.
Key:
- Every rectange represents a different contract, with the contract name in bold at the top. PropertyStorageProxy is also a separate contract, but it is used to 'leech' onto PropertyManagementV1 and essentially become it.
- The solid arrows point to parent contracts of the originator.
- The dashed arrows show where pointers are stored.
First be aware that only certain contracts are upgradeable.
EternalStorage
, PropertyStorageProxy
, and StorageState
cannot be upgraded. Because of this, a key-value storage scheme is used in EternalStorage
so that any type of data scheme can be used. All of these contracts work together to make access to EternalStorage
possible. All data in EternalStorage
is stored in a mapping that maps msg.sender
to the data so that external addresses cannot alter the data.
The rest of the contracts can be upgraded and hold the logic to make the DApp functional.