Skip to content

Case food traceability

linj edited this page Nov 23, 2022 · 2 revisions

Case food traceability

[TOC]

1 Parallel Chain Environment Deployment

2 Contract Compiling

Use the Solidity compiler to compile contract, the following tools are available :

Remix-ide

Intellij-Solidity

2.1 Remix-ide

Create a new solidity contract, and select the compiler version to compile.

remix_prepare

Once compiled, the ABI and Bytecode can be used to create contracts.

remix_compare

  • ABI generated by remix has characters such as newline, whitespace, etc. Chain33 EVM cannot use it directly, and further formatting is required: remove line breaks and whitespace.

  • Chrome does not support copying compiled abi or bin file, so try to use Edge or Internet explorer.

Considering these two points, it is recommended to use Intellij-Solidity plug-ins for compilation.

NOTE:

  • When defining a struct in a contract:
  • Do not define too many elements, or the compiler will declare exception Stack too deep.
  • Do not use nested struct; currently the EVM virtual machine implemented internally by Chain33 does not support nested struct type.

2.2 Intellij-Solidity

2.2.1 Plug-In Installation

Open IntelliJ IDEA, in File->Settings->Plugins, find IntelliJ-Solidity to install。

intelliJ_solidity

2.2.2 Solc Installation

If no geth node is installed locally, you can get the official compiled version of Chain33 directly or use code to compile locally. Otherwise you can use node build-in Solc directly.

2.2.2.1 Native Compilation

Get the latest code to compile, github address: [email protected]:ethereum/solidity.git

Specific installation process refer to Official Document

2.2.2.2 Get the Compiled Version of Chain33

windows: https://bty.oss-ap-southeast-1.aliyuncs.com/solc/solc_0.5.5-windows.zip

linux: https://bty.oss-ap-southeast-1.aliyuncs.com/solc/solc_0.5.5-linux.tar.gz

macOS: https://bty.oss-ap-southeast-1.aliyuncs.com/solc/solc_0.5.5-macOS.tar.gz

2.2.3 Contract Compilation

Use Build->Compile Solidity to compile contract, the compiled results can be seen in the project bar.

compile_solidity

Use the generated abi, bin files for contract creation.

3 Contrct Creation

For details see HERE

4 Case Implementation

To realize a food traceability process is to achieve the origin, production, circulation and other links of traceability.

The actual traceability is a very complicated process, which is reduced to the following steps: farm, food factory, supermarket, food quality inspection department, and user. Properties of the product, take live pigs as an example.

4.1 Information Input

4.1.1 Add Pork Information

Cattle ranches selling

Batch Number Name Weight Date Origin
00001 pig001 500 20190221 NanJing

Call Contract

4.1.2 Add Food Information

Food factory production (for example, ham)

Food number(such as QR code) Name Weight Production Date Packing Date Expiration Date Pork Batch
001 food001 500 20190215 20190220 20210215 00001

Call Contract

4.1.3 Add Quality Control Information

Food quality inspection department sampling

Food number(such as QR code) Test Time Test Results Test Instructions
food001 20190226 Qualified The food is good.

Call Contract

4.1.4 Add Supermarket Shelf Information
Food number(such as QR code) Last Date
food001 20190304

Call Contract

4.1.5 User Rating Update
Food number(such as QR code) User Rating
food001 90

Call Contract

4.2 Information Inquiry

4.2.1 Pork Information Inquiry

Call Contract

4.2.2 Product Information Inquiry

Call Contract

4.2.3 Quality Testing Information Inquiry

Call Contract

Clone this wiki locally