13

I have never written a smart contract before because there is a lot attached to it getting it working. But I finally want to learn it now.

I want to write a simple mininmal working smart contract which prints out something or does something similar to saying "Hello World". Is that possible?

How would such a contract look like? How to deploy it, what tools do I need?

2

1 Answer 1

21

The Greeter tutorial covers a basic Hello World contract. https://ethereum.org/greeter

As a quick summary, I just tested the following steps on Ubuntu 14.04. The install-geth script should also detect and work on other environments.

Note: I had to run the installation script in the first step below twice as it failed the first time.

  • Install geth: bash <(curl -L https://install-geth.ethereum.org)
  • Launch geth in developer mode so that we do not need to fetch the entire blockchain and can mine our own test-ether: geth --dev console
  • Create a test account from geth console : personal.newAccount()
  • Check your account balance (should be 0): eth.getBalance(eth.accounts[0])
  • Start the miner and let it run: miner.start()
  • Attach to geth via a second terminal session: geth attach
  • Check that your account balance has increased: eth.getBalance(eth.accounts[0])
  • Go to the online solidity compiler/editor at https://chriseth.github.io/browser-solidity/. It defaults to a Greeter contract.
  • Copy and paste the greeter's Web3 deploy code to a text editor and replace /* var of type string here */ with "Hello World"
  • Copy and paste the updated code to geth and wait for the Contract mined!.. message
  • Test the contract with greeter.greet()
  • You can destroy the contract with greeter.kill.sendTransaction({from:eth.accounts[0]})
1
  • This was using Ubuntu/Linux. What about other OS? I want to try it on Windows. Can you cover for all OS, new learners will be benefited from it a lot. Commented Nov 13, 2017 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.