Skip to content

A JavaScript example of Ethereum voting Smart Contract deployment and interaction via TestRPC / Web3.

License

Notifications You must be signed in to change notification settings

nikitaeverywhere/edu-ethereum-contract-deployment-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ethereum Contract Deployment Example with web3

This is a JavaScript example of Ethereum voting Smart Contract deployment and a basic interaction with it via TestRPC.

This example:

  • Lists available accounts
  • Compiles a Smart Contract
  • Deploys a Smart Contract
  • Executes Smart Contract's methods
  • Has an UI to interact with the Smart Contract

Voting process:

  • Smart Contract is deployed to Ethereum network with a list of candidates.
  • Everyone in the network can vote for these candidates without limitations (except of their balance).
  • Everyone in the network can check how many votes particular candidate has.

Preview

$ node deployContract.js
Listing available accounts...
Available accounts (10):
0xD5F09bcF69ec2fbbAd5011Fb7E62d5B05F7d7af8
0xE4adB5bc9e3f862095ba1896f219e7931747cF12
0x160Ac5339451ad7e3475d13b56358B6fB7bC2e28
0x8D04B47f415958abe9a7B916306dB2c82F1B9Bb1
0x87e9d9F2D3438849A62eAABa0c2d5a451a459ef2
0xeE17Fc8E7b90D790D3086764C4cCE3023c8e87eF
0x0F1fDA24FAf92EBF623B372D989bd06Bb6D18948
0xE029F41b7160B9205CcD7f66eF891e648790deae
0x5f4dFC0e50e7AdBb96955e5fC6e7e3Cf2d6C319a
0x9970B26671258ba89a9888E428E9a3Ccf1FC04EA
We will deploy contract from account 0xD5F09bcF69ec2fbbAd5011Fb7E62d5B05F7d7af8
Compiling Voting.sol...
Preparing Voting contract to be deployed...
Gas estimation for deploying this contract: 354652
Contract successfully deployed, contract address: 0xb5F5AFe44Cf79DE8b378D781e3BBD5475Da80A40
Let's see how many votes are received for Nick...
Nick has got 0 votes!
Let's vote for Nick as 0xD5F09bcF69ec2fbbAd5011Fb7E62d5B05F7d7af8...
Successfully voted for Nick. Gas used: 43402 Transaction hash: 0x8b7625129d0eec68956d6e2c9b8eb3c84d284593f2560eef73a10f69c5f8f5f9
Let's see how many votes are received for Nick...
Nick has got 1 votes!
Let's vote for Nick as 0xD5F09bcF69ec2fbbAd5011Fb7E62d5B05F7d7af8...
Successfully voted for Nick. Gas used: 28402 Transaction hash: 0xa3429fcf934f31f1c872ee2f1c66a4bba24fe0a815e1458cfb6b9be400242470
Let's see how many votes are received for Nick...
Nick has got 2 votes!
Done. Now open /client/index.html and see contract in action!

2017-11-02_135650

How to Launch This Example

  1. You will need latest NodeJS.
  2. Clone this repository and cd to it.
  3. Run npm install. In case of Windows, before running npm install do this. Any errors in console? Google for them.
  4. Run TestRPC network emulator: ./node_modules/.bin/testrpc.
  5. Run node deployContract.js and see the result.
  6. Open client/index.html file and play with decentralized application from UI!

Voting.ABI.json is just an ABI of compiled contract. Also, deployContract.js script will generate client/votingContractData.js file to access the contract in test network from the client side (client/index.html).

Contributing

Those pull request which update dependencies to their newer versions are very welcome. Due to Ethereum is under active development, its API changes respectively from time to time.

License

MIT © Nikita Savchenko


Original tutorial by Mahesh Murthy.

About

A JavaScript example of Ethereum voting Smart Contract deployment and interaction via TestRPC / Web3.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages