Skip to main content

In this tutorial we continue following Alice in her attempts to monetise her blog posts. Alice has realised that she needs some help with her writing and decides to enlist Edward the editor. Ed has agreed to accept 20% of each contribution Alice receives.

In an earlier tutorial, Alice created a wallet and a very basic app which allowed her readers to transfer Ether via an embedded button, however this will no longer suffice since incoming funds need to be forwarded to multiple accounts. Alice thus endeavours to build a Smart Contract.

Before deploying an actual contract on the Ethereum blockchain, she decides to experiment - aware that mistakes now, may cause problems later.

She chooses to use TestRPC and Truffle which you can install with

npm install -g ethereumjs-testrpc

npm install -g truffle

TestRPC

Ethereum TestRPC is a fast and flexible way to emulate calls to the blockchain without the overheads of running an actual Ethereum node. Features include:

  • Accounts can be re-used and reset.
  • The live blockchain can be forked at a given block to test existing in-the-wild contracts.
  • Specific accounts can be instantiated with a fixed amount of Ether (no need for faucets or mining).
  • Gas price and mining speed can be modifed.

To launch TestRPC run:

testrpc -m "warrior minimum breeze raven garden express solar flavor obvious twenty alpha actress"

This will create a running instance of TestRPC with accounts generated from the "brain wallet" passed in with the -m switch. 
 

TestRPC console output

 

Truffle

Truffle is a framework for rapid development, testing and deployment of smart contracts with Solidity and Javascript. Solidity is a JS-like high level contract language that compiles down to bytecode used in the EVM (Ethereum Virtual Machine).

Running truffle init will create an example project with folder structure

Truffle
├── build/
├── contracts/
├── migrations/
└── test/
  • build contains the compiled version of contracts after running truffle compile
  • contracts is where we will build our Solidity based contracts
  • migrations helps us manage migration of contracts as we make changes over the contracts lifetime
  • test contains Mocha based tests

 

Alice's contract code (truffle create contract AuthorDonationExampleadds AuthorDonationExample.js file in /contracts directory)

Alice's test code ( truffle create test adds AuthorDonationsTestadds AuthorDonationsTest.js file to /test drectory)

 

After writing this draft of her contract Alice realises there are a few problems that need resolved.  The contract will live forever (at least until Serenity is released) and she cannot amend or update it. In her next revision, she will deal with this problem and abstract her solution a little further to create a generic payment button combined with a dynamic smart contract.

 

Part 1 | Part 2 | Part 3 | Part 4 | Part 5

Want to join our team?

Want to start something?

Fantastic! We'd love to hear from you, whethere it's a pitch, an idea or just saying hello!

Feel free to get in touch.

 

Drop us an email?

info@citywebconsultants.co.uk

 

Or give us a call?

+44 (0) 191 906 7746

 

Playing hard to get? We'll contact you