Showing posts with label ethereum. Show all posts
Showing posts with label ethereum. Show all posts

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

"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 https://faucet.metamask.io/ and select "reqest 1 ether from faucet" (or few times) A link like https://ropsten.etherscan.io/tx/0x2bc952af0236ef3960bdcd22b1a637f07e1369b1c0b200063c38104ab9a3611e 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"

SOLIDITY

Now on to the Solidity contract and coding/deployment/testing on the test network. Head towards https://remix.ethereum.org 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 https://ropsten.etherscan.io/tx/0xc551c6c2237c4faad697faf65bdd3d3a407914f1574b2a931871f3552154b93d) - 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: https://ropsten.etherscan.io/tx/0xe3c8af1e041405c53b2bf2ba300a947b3ba2a284f8f0ddce1187658f118557ce
Wait for confirmation - then you can look at the Remix ide, at the bottom, details of the transaction that went through and "decoded input" ....

Friday, 21 September 2018

Fun with Ethereum

Hi, If you want to play with Ethereum, locally, I would suggest to read the following blogs: Demystifying Ethereum Private Blockchain in less than 4 minutes! and Running a “quick” Ethereum private network for experimentation and testing
I run Ubuntu 16 it was a breeze to download the code, compile it, and run a mining node locally, as well as submitting transactions using web3.

Monday, 28 November 2016

Ethereum Wallet is amazingly slow to sync

Since the last hard fork, and I must say, even before that, I am struggling with the use of ethereum mist. What a nightmare, does not sync up, very slow, 27,000 blocks behind and no sync end in view...
According to the logs, worst case, it takes 40 secs to get one block, 27,000 blocks, more than 12 days! What!

Saturday, 19 November 2016

First experience with Ethereum

Some Saturday experiment while the kids are having fun... While drinking coffee... a thought, I want to mine!
Obviously long gone are the days where I could earn BTC while mining on a commodity laptop (about 4 millions years on mine according to the latest number of hashes needed 2^68).
So... with the promise of GPU mining (I am using OpenCL) with Ethereum - I decided to give it a try.
Please note that I am using Ubuntu 16.04
  • Installing the Ethereum wallet was a breeze - quite easy to set up - and interestingly - as part of the set up - I was asked if I wanted to buy some ETH from my Bicoin wallet
  • Of course... I did it - and issued a small transaction from my bitcoin client to the given Ethereum address
  • I issued a small payment of 0.005 BTC (3.74 USD) with a transaction fee of 0.00007329 BTC (0.05 USD). I sent my transaction on 18/11/2016 at 16:39 - and at the time of writing this post, i.e., more than 15 hours later, my transaction is still unconfirmed in the memory pool! If you understand the transaction fees concept and how miners can decide to do whatever they want... it is not surprising that my transaction would be at the bottom of stack. This simply proves, if any proof was needed, that Bitcoin is not ready for micro-payments, and probably will never be until this ASIC mining non-sense - must using ASIC (Application-specific integrated circuit) is sorted out
  • While waiting for my transaction from BTC to ETH to go through... if it ever happens.... I decided to run the mining software in GPU mode, Ethermine
  • I recommend to recompile from the source directly - it is the easiest and fastest way to get going

Blog Archive