Sunday, 11 November 2018

A step-by-step guide for deploying a simple Solidity contract on a test network

This post relates to a simple smart contract written in Solidity deployment on the Ropsten test network. It is a step-by-step deployment, giving as much detail as I could patiently gather..


"MetaMask is a bridge that allows you to visit the distributed web of tomorrow in your browser today. It allows you to run Ethereum dApps right in your browser without running a full Ethereum node.".
In a nutshell, it allows you to create an address and request ETH for testing. Install the extension for Chrome or Mozilla and set it up as follows. Start with the password creation (in my test I used 12345678910!)
You will now see this screenshot:
Then accept the various terms and conditions Finally, set up the secret words and back them up (spray talk duck avocado access put lens slice bench donor wise survey) - and the next screen put them back in the same order - and confirm. You will still see the following.
Now for the purpose of this exercise, select the "Ropsten Test Network" and click on "deposit" and select "Test Faucet" and click "GET ETHER" A new tab opens to and select "reqest 1 ether from faucet" (or few times) A link like will appear once the transaction(s) has(have) been validated and mined - you will see the number of ETH appear on your METAMASK main window for the "Ropsten Test Network"


Now on to the Solidity contract and coding/deployment/testing on the test network. Head towards Under the tab 'run' select (if not already) 'environment' to be 'Injected Web' - and the test account we created should appear with the number of ETH requested by Faucet. We just need to write and deploy a contract... What about a simple contract to store the hash of a public document to validate the fact that it has not been modified?
pragma solidity ^0.4.7;

contract HashedDocsDemo {
    mapping (string => string) urlsDocHashMaps;
    function setHash(string url, string hash) public validStr(url) validStr(hash) {
        urlsDocHashMaps[url] = hash;
    function checkHash(string url, string hash) public view validStr(url) validStr(hash) returns(bool) {
        string memory storedHash = urlsDocHashMaps[url];
        return keccak256(bytes(storedHash)) == keccak256(bytes(hash));
    modifier validStr(string str) {
        bytes memory bstr = bytes(str); 
        require(bstr.length != 0, "invalid string");
Once the contract has been pasted in the Remix IDE, go to "run" and click on deploy.
A window will popup and "click" confirm.
Another URL will be displayed (like - same thing - wait for mining and effective contract deployment ("This transaction has been included into BlockNo #4400698 And will be reflected in a shortwhile")
We can finally interact with the contract - still in Remix - in the Run tab Enter any URL with any hash - then "transact" - same pop-up - confirm a new link is displayed:
Wait for confirmation - then you can look at the Remix ide, at the bottom, details of the transaction that went through and "decoded input" ....

No comments:

Blog Archive