Coding/Deploying Simple a Smart Contract

1.1: Set up your Truffle project

The first step in setting up and configuring your Truffle project is to edit your configuration file.

Launch your VM (from previous labs) and open the Terminal app.

1. $ cd ~

2. $ cd myProject

3. Launch Ganache

4. In the main Ganache window, note the port number under RPC Server (most likely 7545)

5. Return to the Terminal app

6. Launch VS code in the current directory:

7. $ code

8. Click truffle-config.js in the VS Code Explorer column to open the truffle-config.js file in the

editor window.

9. Remove the comments starting at line 45 to make your config file section that defines your

blockchain connection for the development network look like the example in the textbook (page

113).

10. Change the port: setting to the port your Ganache blockchain is using (from step 5 above)

11. Save the truffle-config.js file. (Ctrl-S or File -> Save)

12. Create a screenshot of the results of steps 9 – 12 and paste it into your Lab Report File.

1.2: Deploy and Use Your First Smart Contract

Follow the instructions in the book for Coding Your First Smart Contract (page 116).

1. In VS Code, create a new file in the contracts directory, HelloWorld.sol.

2. Type the code for HelloWorld.sol (page 116).

a. Change (string) in line 6 to (string memory)

3. Change the first line of HelloWorld.sol to: pragma solidity ^0.5.0;

4. Save your file

5. Create a new file in the migrations directory, 2_contracts_migrations.js.

6. Type the code in the textbook for step 3 on page 118.

7. Save your file.

8. Create a screenshot of the results of steps 6 – 7 and paste it into your Lab Report File.

9. Open a new terminal in VS code (Terminal -> New Terminal)

10. $ truffle compile

11. If Ganache is not running, launch Ganache

12. $ truffle deploy –reset

13. $ date

14. Create a screenshot of the results of steps 11 – 12 and paste it into your Lab Report File.

15. $ truffle console

16. Type the command found on page 123 to return an instance of the deployed HelloWorld.sol

contract.

17. Create a screenshot of the results of step 15 and paste it into your Lab Report File.

18. Type the command found on the bottom of page 123 to invoke the getHelloWorld() function of

the smart contract HelloWorld.sol.

a. Replace getHelloWorld() with getHelloMessage()

19. Create a screenshot of the results of step 17 and paste it into your Lab Report File.

20. > .exit

Section 2: Wrapping up

1. In Windows PowerShell, shut down your Ethereum development virtual machine:

1. PS %HOME%\vagrant\BLCN631eth> vagrant halt

2. Create a snapshot (NOT A SCREENSHOT) of your Ubuntu VM in VirtualBox. This allows you to

easily restore to this point if you ever need to “undo” subsequent steps and return to a known

point.

a. PS %HOME%\vagrant\ BLCN631eth > vagrant snapshot save EndOfLab03

You should have 5 screenshots in your Lab Report File. Save your file

Set up your new Truffle project
The first step in setting up and configuring your new Truffle project is to initialize a new projects and edit your configuration file. Launch your VM (from previous labs) and open the Terminal app.

1.$ cd ~

2.$ mkdir supplyChain

3.$ cd supplyChain

4.$ truffle init

5.Launch Ganache

6.$ code .

HINT: Instead of following steps 7 -9, you can just copy the truffle-config.js file from the myProject directory into this directory.

$ cp ../myProject/truffle-config.js ./truffle-config.js

7.Click truffle-config.js in the VS Code Explorer column to open the truffle-config.js file in the editor window.

8.Remove the comments starting at line 45 to make your config file section that defines your blockchain connection for the development network look like the example in the textbook (page 113).

9.Change the port: setting to the port your Ganache blockchain is using (from step 5 above)

10.Save the truffle-config.js file. (Ctrl-S or File -> Save)

1.2: CREATE 3 NEW SMART CONTRACTS
In this section you’ll create 3 new smart contracts and update another.

1.Using Firefox in your Ubuntu VM, login to this course in Blackboard (iLearn) and access this week’s content.

2.Download the following files from the Lab 4 assignment section in Blackboard:

a.erc20Interface.sol

b.erc20Token.sol

c.SupplyChain.sol

d.2_contract_migrations.sol

3.Copy erc20Interface.sol, erc20Token.sol, and SupplyChain.sol to the SupplyChain/contracts directory.

4. Copy 2_contract_migrations.sol to the SupplyChain/migrations directory.

5.In VS Code, open each smart contract you just copied to ensure their contents look like to files you downloaded.

6.Open a new terminal in VS code (Terminal -> New Terminal)

7.$ truffle compile

8.$ date

9.Create a screenshot of the results of steps 7 – 8 and paste it into your Lab Report File.

SECTION 2: Exploring Smart Contracts
Explore smart contract events
1.In VS Code (in the SupplyChain project), open erc20Interface.sol smart contract.

The erc20Interface.sol file is an interface, which defines the minimum functionality of a class of contracts. Any contract that implements this interface must provide code to define the functions and elements in this interface.

2.Note the 2 event that this interface defines.

3.Create a screenshot of the erc20Interface.sol file showing the 2 defined events and paste it into your Lab Report File.

4.Open erc20Token.sol smart contract.

The erc20Token.sol file implements the erc20Interface.sol interface, which defines the functionality required by the interface.

5.Find where the ERC20Token contract triggers the Transfer event.

6.Create a screenshot of the erc20Token.sol file showing the Transfer events being triggered and paste it into your Lab Report File.

7.Open SupplyChain.sol smart contract.

The SupplyChain.sol file contains the functionality for the supply chain smart contract.

8.Find where the supplyChain contract triggers the TransferOwnership event.

9.Create a screenshot of the SupplyChain.sol file showing the TransferOwnership event being triggered and paste it into your Lab Report File.

Explore smart contract ownership
1.In VS Code, open SupplyChain.sol smart contract.

2.Find the onlyOwner() modifier definition. As the comment indicates, this modifier will only allow a product owner to carry out an action.

3.Find where the onlyOwner() modifier is used in the supplyChain contract.

4.Create a screenshot of the SupplyChain.sol file showing where the onlyOwner() modifier is used and paste it into your Lab Report File.

5.In your Lab Report file, describe how the supplyChain contract uses the onlyOwner() modifier and what would be possible if it was not added to the smart contract’s code? In other words, what does the onlyOwner() modifier prevent?

SECTION 3: Deploy and Test Smart Contracts
In this section of your lab you will deploy your new smart contracts to Ganache and test their functionality.

Deploy smart contracts
1.In VS Code (in the SupplyChain project), open a new terminal in (Terminal -> New Terminal)

2.$ truffle compile

3.If Ganache is not running, launch Ganache

4.$ truffle deploy –reset

5.$ date

6.Create a screenshot of the results of steps 2 – 5 and paste it into your Lab Report File.

3.2: Test smart contract functions
In the next few steps you will use Truffle to fetch the deployed address of the supplyChain contract, add 1 participant and 2 products, and then display the products you just created.

1.$ truffle console

2.> supplyChain.deployed().then(function(instance) {return instance });

3.> supplyChain.deployed().then(function(instance) {return instance.addParticipant(“0”, “Participant A”,”passA”,”Manufacturer”,accounts[0]) });

4.> supplyChain.deployed().then(function(instance) {return instance.addProduct(“12345”, 0, “Model 100”, “100”, “123”, 11, 7, 0) });

5.> supplyChain.deployed().then(function(instance) {return instance.addProduct(“56789”, 0, “Model 101”, “101”, “456”, 12, 8, 0) });

6.> supplyChain.deployed().then(function(instance) {return instance.getProduct(0) });

7.> supplyChain.deployed().then(function(instance) {return instance.getProduct(1) });

8.> .exit

9.$ date

10.Create a screenshot of the results of steps 7 – 9 and paste it into your Lab Report File.

Section 4: Wrapping up
1.In Windows PowerShell, shut down your Ethereum development virtual machine:

1.PS %HOME%\vagrant\BLCN631eth> vagrant halt

2.Create a snapshot (NOT A SCREENSHOT) of your Ubuntu VM in VirtualBox. This allows you to easily restore to this point if you ever need to “undo” subsequent steps and return to a known point.

a.PS %HOME%\vagrant\ BLCN631eth > vagrant snapshot save EndOfLab04

You should have 7 screenshots and 1 explanation in your Lab Report File. Save your file

Install Web3 (You’ll install Web3 for Python)
1.1: Update Ubuntu’s Python to 3.7
The first step in setting up Web3.py (Web3 for Python) is to upgrade Python to version 3.7.

1.Open PowerShell

2.PS %HOME%> cd vagrant\BLCN631hlf

3.PS %HOME%\vagrant\BLCN631hlf> vagrant up

4.Login to your Linux VM and open a new Terminal window

5.$ sudo apt update

6.$ sudo apt install software-properties-common

7.$ sudo add-apt-repository ppa:deadsnakes/ppa

Press ENTER when prompted to continue

8.$ sudo apt update

9.$ sudo apt -y install python3.7

10.$ date

11.Create a screenshot of the results of steps 9 – 10 and paste it into your Lab Report File.

1.2: Define virtual environment and install web3.py
The next step is to define a Python virtual environment and install Web3.py in that environment.

1.$ sudo apt-get update

2.$ sudo apt-get -y upgrade

Choose ‘install the package maintainer’s version’ menu option when prompted

3.$ sudo apt-get -y install build-essential

4.$ sudo apt-get -y install python3.7-dev

5.$ date

6.Create a screenshot of the results of steps 4 – 5 and paste it into your Lab Report File.

7.$ sudo apt-get -y install python3.7-venv

8.$ cd ~

9.$ git clone https://github.com/ethereum/web3.py.git

10.$ cd web3.py

11.$ python3.7 -m venv venv # create virtual environment venv

12.$ . venv/bin/activate # activate virtual environment venv # Note: there is a space after ‘.’

13.Create a screenshot of the results of steps 10 – 12 and paste it into your Lab Report File.

14.$ pip install –upgrade pip

15.$ pip install -e .[dev]

16.Create a screenshot of the results of step 15 and paste it into your Lab Report File.

Section 2: Explore Python Ethereum Test Procedures and Deploy
1.Launch the Firefox browser in your Ubuntu VM.

2.Go to the Blackboard site (ucumberlands.blackboard.com) and login.

3.Navigate to this course (BLCN631) -> Content for this week, Lab05.

a.Download the buildSupplyChain.py file and copy it to the $HOME\supplyChain directory.

b.Download the participants.csv file and copy it to the $HOME\supplyChain directory.

c.Download the products.csv file and copy it to the $HOME\ supplyChain directory.

d.Download the showEvents.py file and copy it to the $HOME\ supplyChain directory.

e.Download the ShowState.py file and copy it to the $HOME\ supplyChain directory.

f.Download the showSupplyChain.py file and copy it to the $HOME\ supplyChain directory.

g.Download the showSupplyChainComplete.py file and copy it to the $HOME\ supplyChain directory.

h.Download the transfers.csv file and copy it to the $HOME\ supplyChain directory.

4.Launch Ganache

5.$ cd ~/supplyChain

6.$ code .

7.In VS Code, open SupplyChain.sol (in the contracts directory)

8.Copy ALL the code to the clipboard. (Ctrl-A, Ctrl-C)

9.Back in Firefox, navigate to http://remix.ethereum.org

10.Click the SOLIDITY Environment button.

11.Click File Explorers (left hand menu)

12.Click Create New File and enter SupplyChain.sol for the name.

13.Copy the code for SupplyChain.sol from VS Code and paste it into the Remix editor.

14.Click Solidity Compiler (left hand menu), then the Compile SupplyChain.sol button to compile the SupplyChain.sol smart contract.

15.Create a screenshot of the results of step 13 and paste it into your Lab Report File.

16.Once the compile completes, click the ABI link at the bottom of the compiler frame to copy the SupplyChain ABI to your clipboard.

17.In VS Code, create a new file in the supplyChain directory named SupplyChain.abi.

18.Paste the ABI content you copied from Remix into the editor window, then save the file.

19.Create a screenshot of the results of step 17 and paste it into your Lab Report File.

20.In Remix, click Deploy & run transactions (left hand menu).

21.In the Remix Environment dropdown, select Web3 providers, the change the port to 7545 in the Web3 Provider Endpoint fill-in and click OK.

22.Click Deploy, then click the Copy Value to Clipboard next to the SUPPLYCHAIN contract under Deployed Contracts to copy the address of SupplyChain to your clipboard.

23.Create a screenshot of the results of step 21 and paste it into your Lab Report File.

24.In VS Code, open buildSupplyChain.py, then click Install to install the Python extension.

25.Open each of the files below and replace the address value for web3.toChecksumAddress(‘ADDRESS’) with the address you copied from Remix: (then save each file)

a.buildSupplyChain.py

b.showEvents.py

c.showState.py

d.showSupplyChain.py

e.showSupplyChainComplete.py

26.Create a screenshot of the results of step 25 and paste it into your Lab Report File.

27.Run buildSupplyChain.py (green arrow in the upper right-hand corner)

28.Create a screenshot of the results of step 27 and paste it into your Lab Report File.

29.Run showSupplyChainComplete.py.

30.Create a screenshot of the results of step 29 and paste it into your Lab Report File.

Section 3: Wrapping up
1.Close all open windows in your Ubuntu VM.

2.In Windows PowerShell, shut down your Ethereum development virtual machine:

3.PS %HOME%\vagrant\BLCN631eth> vagrant halt

4.Create a snapshot (NOT A SCREENSHOT) of your Ubuntu VM in VirtualBox. This allows you to easily restore to this point if you ever need to “undo” subsequent steps and return to a known point.

a.PS %HOME%\vagrant\ BLCN631eth > vagrant snapshot save EndOfLab05

You should have 10 screenshots in your Lab Report File. Save your file

Sample Solution

he similarities and differences between the Australian and Chinese economies provide an interesting comparison of economic systems throughout the world. They both differ and coincide with each other’s economic growth, environmental sustainability and the role of each of their governments. Since the late 1970’s, china has begun to move from a closed, centrally planned system to a more market-orientated one that plays a major global role, proven by becoming the world’s largest global exporter in 2010. Australia on the other hand, also has an economy that has witnessed many high and low points over the last few decades. Australia has an incredibly prosperous mixed market economy, which defines as an economic system blending elements of market economies with elements of planned economics, free markets with state interventionism, or private enterprise with public enterprise. Its free market is among the first five developed countries of the world, with the four main components being trade, manufacturing, and services and financing. A free market defines as a system in which the prices for goods and services are determined by the open market and by consumers. China on the other hand is governed or ruled by a socialist market economy where the government allows limited free enterprise while still continuing to maintain full control over its resources. Although China is ruled by this system, it has become incredibly successful for trade to and from china. Therefore overall, Australia and China’s differing market systems do and will result in both successful and varying levels of growth and use of resources, the role of government in health-care and education.

China’s mainly socialist market eco

This question has been answered.

Get Answer
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, Welcome to Compliant Papers.