This repository contains an Ethereum Contract to demonstrate a contract's functionality as well as the interaction with it. It is based on a truffle project which should do the whole deployment process for you. Nevertheless, some prerequisites need to be installed in advance.
For truffle to run, you need a working installation of node.js. Please follow the instructions for your Operating System:
Ganache is a simulation environment for an Ethereum Blockchain. It will set up a private Ethereum Blockchain with a number of Demo-Accounts (who already have Ethers) and it has a tight truffle-integration (since it's a subproject of truffle). Truffle will compile the smart contract for you and deploy it to the ganache blockchain.
Please follow the installation instructions for your operating system:
- Account A deploys a Smart Contract which requests some kind of product. Account A becomes the contract owner
- Account B places a bid to the smart contract
- Account C places a lower bid to the smart contract
- Some account (not the owner) tries to accept the bid, which should not work: only the contract owner can accept the lowest bid
- The owner tries to accept the bid, but without sending enough Ether to the contract. Contract rejects.
- The owner accepts the bid and sends the necessary amount of Ether to the contract
- Account C sets the serial number of the product to be shipped to the contract
- Contract owner signals that everything worked out fine to the contract. The contract now sends the Ethers to Account C.
After installing node, truffle and ganache, clone this repository somewhere on your machine. Now do the following steps:
- Change to the truffle project directory you just cloned (using a shell or some command prompt tool)
- Start Ganache, create a new workspace and link the truffle project to it (see Ganache User Interface)
- In the project directory, run
npm install truffle-assertions
(also see here). This package is required to smoothely run the JavaScript test cases - In the project directory, run
truffle migrate
. This will compile the solidity contract and deploy it as the first demo account which was created by ganache. You should see the demo accounts and the contract in Ganache, too. Ganache has to be running for this step! - Run
truffle test
. This will start the Use Case implemented as JavaScript test cases. Ganache has to be running for this step!
I suggest you write your own code using web3js
. Read the docs for installation and some examples here. For a simple demo code, see the file demo.js
, which contains a (very small) example connecting to an MQTT broker and executing a value transfer between two involved (fixed) parties.