Skip to content

Distributed supply chain application (DApp) that uses a Solidity smart contract to track pharmaceuticals on the Ethereum blockchain.

Notifications You must be signed in to change notification settings

brandon-zimmerman/ethereum-supply-chain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ethereum Pharmaceutical Supply Chain

The goals of this project are as follows:

  • Plan the project with write-ups.
  • Write smart contracts.
  • Test smart contract code coverage
  • Deploy smart contract on public test network.
  • Create web client to interact with smart contract

Overview

This project is a Distributed Application (DApp) which includes an Ethereum smart contract and a web front-end. The smart contract represents a pharmaceutical supply chain implemented with Solidity .


Supply Chain Smart Contract

The Supply Chain smart contract (SupplyChain.sol) is implemented using Solidity. The contract inherits from a contract that provide ownership (Ownable.sol) functions. And contracts based on the Role contract (Roles.sol) that implement role-specific functions (ManufacturerRole.sol, DistributorRole.sol, RetailerRole.sol, and ConsumerRole.sol).

UML Diagrams

UML diagrams describing the contracts and their interactions are listed below.

Item Struct

The Supply Chain contract includes a struct named Item (SupplyChain.sol lines -38-54) which holds item information including the current owner, manufacturer, distributor, retailer, and consumer information.)


Smart Contract Unit Tests

Unit tests are located within TestSupplychain.js. They are implemented in JavaScript using the Truffle framework. The tests can be run by starting Ganache and executing the following commands (from a Windows Command prompt) from the main project folder.

C:\truffle.cmd develop

truffle(develop)>test

Truffle will compile the solidity contracts located under contracts , then deploy the contracts to Ganache and execute the tests located under test. An image of the truffle test execution is below.

Truffle tests


Deploying to the Ethereum RINKEBY Test Network

Truffle is used to deploy the smart contracts to a target network. The truffle configuration file (truffle-config.js) controls where Truffle deploys the project's contracts. A screenshot of the truffle-config.js file is shown below. The config file contains deployment parameters for two networks: development and rinkeby.

require('dotenv').config();
var HDWalletProvider = require('truffle-hdwallet-provider');
var infuraUrl = 'https://rinkeby.infura.io/v3/' + process.env.INFURA_API_KEY;

module.exports = {
  networks: { 
	development: {
		host: '127.0.0.1',
		port: 7545,
		network_id: "*"
	}, 
	rinkeby: {
        provider: function() {
            return new HDWalletProvider(process.env.MNEMONIC, infuraUrl) 
		},
      	network_id: 4,
        gas: 4500000,
        gasPrice: 10000000000,
    }
  }
};

The rinkeby network configuration tells Truffle to deploy the smart contracts to the RINKEBY test network through the Infura blockchain infrastructure. The wallet mnemonic and RINKEBY API key values are retrieved from the .env file using the dotenv node.js module.

Running the following commands will initiate the deployment to the RINKEBY test network.

cd contracts
truffle migrate --network rinkeby

truffle migrate


Web Front-End

The project includes an HTML test client (index.html) that interacts with the contract on the Ethereum RINKEBY test network. The front-end uses the Web3 Ethereum JavaScript API to interact with the supply chain contract on the RINKEBY test network through the MetaMask browser plug-in.

Here is a screen shot of the web client.

Supply Chain Client

The interface interacts with the smart contract to move a drug through the supply chain process; from manufacture to purchase by the end consumer.


Configuring the Project

Require Software

The following software must be installed on the host machine.

  • Install Ganache

    Download and install the version of Ganache for your operating system.

  • Install Truffle

    Run the following command

    npm install truffle -g
  • Install MetaMask

    Install the MetaMask Chrome extension.

  • Install Node.js dependencies

    The following node installation command should be executed from the project root directory.

    npm install

Infura Account

The project requires an Infura account. You can create one here.

Create an .env file

The truffle test and migration process requires a file named .env to be located in the root folder. This file must contain your wallet mnemonic and Infura API URL.

INFURA_API_KEY=<INFURA API KEY GOES HERE>
MNEMONIC="<WALLET MNEMONIC GOES HERE"

About

Distributed supply chain application (DApp) that uses a Solidity smart contract to track pharmaceuticals on the Ethereum blockchain.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published