以太坊公链私链_如何使用以太坊构建汽车制造供应链系统

以太坊公链私链

by Marcelo Russi Mergulhão

由Marcelo RussiMergulhão

如何使用以太坊构建汽车制造供应链系统 (How to build a car manufacturing supply chain system using Ethereum)

Here at Daitan we are always looking for new technologies that can help our clients solve their problems more efficiently. Lately one that has captured a lot of our and our clients’ attention is Blockchain.

Daitan,我们一直在寻找可以帮助我们的客户更有效地解决其问题的新技术。 最近吸引了我们和我们客户很多注意力的是区块链。

In this article, our goal is to present a practical way of implementing your own supply chain application based on a blockchain platform!

在本文中,我们的目标是提出一种基于区块链平台实现自己的供应链应用程序的实用方法!

The system is used for one of the problems where I think applying blockchain gives the highest value: a supply chain.

该系统用于我认为应用区块链可带来最高价值的问题之一:供应链。

This application has been explored a lot lately on PoCs and huge companies are already experimenting with that for their operations.

最近在PoC上对该应用程序进行了很多研究,并且大公司已经在对其操作进行试验

Using blockchain to solve this type of problem is a good alternative because we can benefit from the transparency and efficient provenance tracking inherent to the technology.

使用区块链解决此类问题是一个很好的选择,因为我们可以从该技术固有的透明性和有效的出处跟踪中受益。

Since this article intends to be simple and not a complete project, we will streamline the problem a lot.

由于本文旨在简单而不是完整的项目,因此我们将大大简化该问题。

At the end, we still have an end-to-end system that can demonstrate the applicability of the technology to this particular set of problems.

最后,我们仍然有一个端到端系统,可以证明该技术对这组特定问题的适用性。

选择平台 (Choosing a Platform)

Currently there are a lot of platforms that allow you to make your own blockchain or use a public blockchain for your own projects, so we will leverage one instead of building from scratch.

当前,有许多平台可让您创建自己的区块链或将公共区块链用于自己的项目,因此我们将利用一个平台,而不是从头开始构建。

These projects have a lot of backing from players from both enterprises and the open source community, so we believe that using one is the most practical path for the majority of problems, allowing us to focus on the business logic instead of the infrastructure.

这些项目在企业和开放源代码社区的支持下都有很多支持,因此我们认为使用“一个”解决大多数问题是最实际的途径,这使我们能够专注于业务逻辑而不是基础架构。

For our demo we chose the Ethereum Project. It is a popular platform and all the development tools available make implementation of solutions over it easy to accomplish.

对于我们的演示,我们选择了以太坊项目 。 它是一个流行的平台,所有可用的开发工具都使解决方案的实现变得容易完成。

制造故事 (The Manufacturing Story)

We have established the domain, but what specifically do we intend to make?Let’s describe a simple car manufacturing problem and the players involved in the process.

我们已经建立了这个领域,但是我们打算做什么?让我们描述一个简单的汽车制造问题以及过程中涉及的参与者。

First, we have the parts factory, responsible for producing wheels, body parts, engines and transmissions. The factory informs each part production using the “ProductManagement” smart contract, which will keep details about each part and product.

首先,我们有零件工厂,负责生产车轮,车身零件,发动机和变速器。 工厂使用“ ProductManagement”智能合约通知每个零件生产,该合约将保留每个零件和产品的详细信息。

Additionally, the factory states that it is the owner of a specific part by calling a method from the “ChangeOwnership” smart contract, which will keep the owner history of each part and product.

此外,工厂通过从“ ChangeOwnership”智能合约中调用方法来声明特定零件的所有者,该方法将保留每个零件和产品的所有者历史。

Going further on the chain, we have a car factory that buys parts from the part factory to manufacture cars. The “ChangeOwnership” contract is where we keep this type of operation, so we have another method to allow the parts factory to transfer the part ownership to the car factory.

更进一步,我们有一家汽车厂,从零件厂购买零件以制造汽车。 “ ChangeOwnership”合同是我们进行此类操作的地方,因此我们有另一种方法允许零件工厂将零件所有权转让给汽车工厂。

With enough parts, the car factory can finally start to manufacture cars. Similar to what the parts factory did to inform its job, the car factory now uses the “ProductManagement” smart contract to state a specific car assembly. Each car has a set of properties, like a serial number, and also has a parts list, that ties cars to specific parts.

有了足够的零件,汽车工厂终于可以开始制造汽车。 与零件工厂通知其工作类似,汽车工厂现在使用“ ProductManagement”智能合约来声明特定的汽车装配体。 每辆汽车都有一套属性,例如序列号,还有零件清单,这些清单将汽车与特定零件联系在​​一起。

The ownership is controlled by the “ChangeOwnership” contract and so the car factory sets that car ownership to itself.

所有权由“ ChangeOwnership”合同控制,因此汽车制造厂将汽车所有权设置为自己。

Finally, we add dealers to the scenario and they can buy cars from a factory and the latter can transfer the car ownership using “ChangeOwnership”. The blockchain stores every transaction that involved that car or any of the parts that compose it, so the dealer (or any other part) can track everything that a specific item has gone through. In our case this tracking will be done by watching the events generated by the transactions. This will become clear when we analyze the code.

最后,我们将代理商添加到方案中,他们可以从工厂购买汽车,后者可以使用“ ChangeOwnership”转让汽车所有权。 区块链存储涉及该汽车或其组成部分的每笔交易,因此经销商(或任何其他部分)可以跟踪特定物品经历的所有事情。 在我们的案例中,将通过观察事务生成的事件来完成此跟踪。 当我们分析代码时,这将变得很清楚。

The complete product flow can be seen in the picture below:

下图显示了完整的产品流程:

We know what to do, but we still need to arm ourselves with some tools to enable the development.

我们知道该怎么做,但是我们仍然需要使用一些工具来进行开发。

环境与工具 (Environment and Tools)

First, we need to make a clear distinction between the networks of the Ethereum ecosystem. The main network (called Mainnet) is where the real apps reside and where each unit of ether has real value.

首先,我们需要明确区分以太坊生态系统的网络。 主网络(称为Mainnet)是真正的应用程序所在的地方,并且每个以太单元都有实际价值。

This mean that everything you record there is bound to exist as long as Ethereum itself exists. Additionally, ether can only be obtained by mining or by buying it with real money.

这意味着只要以太坊本身存在,您记录的所有内容就必然存在。 此外,以太只能通过采矿或用真钱购买来获得。

Using that network to develop demonstrations seems like a bad idea, so there are other networks that are better at supporting development. These networks can be public networks, like the one called Rinkeby, or you can even create your own Ethereum network!

使用该网络进行演示似乎不是一个好主意,因此还有其他一些网络更能支持开发。 这些网络可以是公共网络,例如称为Rinkeby的网络,或者您甚至可以创建自己的以太坊网络!

While using a public Test Net like Rinkeby provides us a better way to validate our DApp (Decentralized App), we will create our own network to shorten the transaction acceptance time and simplify the development the most.

尽管使用Rinkeby之类的公共测试网为我们提供了一种更好的方法来验证DApp(去中心化应用程序),但我们将创建自己的网络以缩短交易接受时间并最大程度地简化开发。

The tool we will use to create our network is called Ganache.

我们用于创建网络的工具称为Ganache

Ganache is a simple tool that creates a local Ethereum network and you can connect to it just like you would with the main network. It also provides you with 10 accounts with 100 ether every time you run it.

Ganache是​​创建本地以太坊网络的简单工具,您可以像使用主网络一样连接到该网络。 每次运行时,它还为您提供10个带有100个以太币的帐户。

I like to live on the terminal, so instead of using the Ganache UI, I will use ganache-cli, the command line version of Ganache that is a NodeJS-based tool and can be installed with npm:

我喜欢住在终端上,因此,我将使用ganache-cli ,而不是使用Ganache UI,该命令行版本的Ganache是​​基于NodeJS的工具,可以与npm一起安装:

npm install -g ganache-cli

npm install -g ganache-cli

To run, just execute ganache-cli and you are good to go! When you run the CLI, it will generate a mnemonic for your wallets. The mnemonic is a 12-word phrase that is the root for generating the account private keys and consequently the wallets.

要运行,只需执行ganache-cli ,您就可以开始了! 运行CLI时,它将为您的钱包生成一个助记符。 助记符是一个12字的短语,它是生成帐户私钥并因此生成钱包的根。

The output is like the following image:

输出如下图所示:

Save the mnemonic to use later. Whenever you need to run Ganache again you can preserve the same accounts providing the mnemonic with the -m parameter:

保存助记符以供以后使用。 每当您需要再次运行Ganache时,您都可以保留相同的帐户,并为它们提供-m参数的助记符:

ganache-cli -m "now frame tenant chronic oven cube minute immune leaf clock demand volume"

ganache-cli -m "now frame tenant chronic oven cube minute immune leaf clock demand volume"

Note: mnemonics created by Ganache are not safe and should not be used for wallets on the Ethereum network

注意:由Ganache创建的助记符并不安全,不应用于以太坊网络上的钱包

Now that we have our network we need to be able to test and deploy our contracts to it. This is accomplished by another tool called Truffle, part of the same development suite as Ganache. Truffle can also be installed with npm, so just run:

现在我们有了我们的网络,我们需要能够测试和部署我们的合同。 这是通过另一个名为Truffle的工具完成的,该工具与Ganache属于同一开发套件。 松露也可以通过npm安装,因此只需运行:

npm install -g truffle

npm install -g truffle

We will use Truffle to prepare our project structure, so run truffle init and check the folder structure that is created:

我们将使用Truffle来准备我们的项目结构,因此运行truffle init并检查创建的文件夹结构:

ethereum-supply-chain|-contracts| — Migrations.sol|-migrations| — 1_initial_migration.js|-testtruffle-config.js
  • Contracts: contains the code for our smart contracts

    合约:包含我们智能合约的代码
  • Migrations: contains the deployment instructions to our contracts

    迁移:包含我们合同的部署说明
  • Test: contains the tests for the contracts

    测试:包含合同的测试
  • Truffle-config.js (or truffle.js depending on your O.S.): main configuration file, points to the Ethereum networks that we can deploy to

    Truffle-config.js(或取决于您的操作系统,为truffle.js):主配置文件,指向我们可以部署到的以太坊网络

The configuration file comes with a lot of content, but most of it is commented. To add our local network to the deployment options just uncomment the following part (lines 49–53):

配置文件包含很多内容,但是大多数内容都带有注释。 要将我们的本地网络添加到部署选项,只需取消注释以下部分(第49-53行):

Finally, we need to provide an interface to our users to let them interact with the Ethereum networks.

最后,我们需要为用户提供一个界面,以使他们与以太坊网络进行交互。

One of the options for this is to install Metamask, a browser plugin that manages wallets and also enables web systems to speak with the Ethereum networks.

一种选择是安装Metamask ,这是一个浏览器插件,可以管理钱包,还可以使Web系统与以太坊网络对话。

Once installed, Metamask provides an interface to check wallet funds on different networks. Whenever a web system requires an operation that involves payment, Metamask asks for user approval.

安装完成后,Metamask将提供一个界面来检查不同网络上的钱包资金。 每当网络系统需要涉及支付的操作时,Metamask都会要求用户批准。

To install it, just go to their website and choose the extension to your browser.

要安装它,只需访问他们的网站并选择浏览器的扩展名即可。

After the installation, Metamask needs to create or import a wallet, so choose “import with seed phrase” and paste the mnemonic you got from ganache-cli.

安装后,Metamask需要创建或导入钱包,因此选择“使用种子短语导入”,然后粘贴从ganache-cli获得的助记符。

Note: Metamask is currently in beta, so keep that in mind whenever you use it and follow the instructions given after configuration

注意:Metamask当前处于测试阶段,因此在使用它时请记住这一点,并按照配置后给出的说明进行操作

And that is all we need for now, let’s dive into the code!

这就是我们现在所需要的,让我们深入研究代码!

智能合约动手 (Smart Contracts Hands On)

The first thing we need to do is to implement the logic behind each of the smart contracts, so we begin with “ProductManagement”.

我们要做的第一件事是实现每个智能合约背后的逻辑,因此我们从“ ProductManagement”开始。

This contract should have one method for registering parts and another to register products, even if the requirements for each operation are very similar.We do that because we want to check that all the parts exist when we try to build a new product. So we can have the following methods:

即使每个操作的要求非常相似,此合同也应该有一种注册零件的方法,另一种注册产品的方法。之所以这样做,是因为我们在尝试构建新产品时要检查所有零件是否存在。 因此,我们可以采用以下方法:

  • Part registration: create a mapping given the details of the part itself (type, serial number and manufacturing date), the factory that made it (factory id) and the current owner (owner id).

    零件注册:创建一个映射,其中给出了零件本身的详细信息(类型,序列号和生产日期),制造该零件的工厂(工厂ID)和当前所有者(所有者ID)。
  • Product registration: create a mapping given the same as part registration plus the id of each of the parts present on the product.

    产品注册:创建与零件注册相同的映射以及产品上存在的每个零件的ID。
  • Getters for the mappings so that we can check parts’ and products’ existence and get their details.

    映射的吸气剂,以便我们可以检查零件和产品的存在并获取其详细信息。

The contract code that we need to implement that is:

我们需要实现的合同代码是:

We define structs for parts and products that map all the information required to “build” our parts and products, and after that we add the mappings that will keep all registered items.

我们为零件和产品定义结构,以映射“构建”零件和产品所需的所有信息,然后添加将保留所有已注册项目的映射。

The buildPart method is simple: it uses a helper function to concatenate the sender address and part information on a bytes array and calculate a hash. This hash is the key used when registering and later querying the data, so we return it to aid development.

buildPart方法很简单:它使用帮助程序函数将发送方地址和部件信息连接到字节数组上,并计算哈希值。 该哈希是注册和稍后查询数据时使用的密钥,因此我们将其返回以帮助开发。

Since Ethereum transactions are not validated and run when you call the smart contract, we receive a transaction hash and can’t use it for our web app, but we can issue a call instead of a transaction to check the results easily.

由于以太坊交易在您调用智能合约时未得到验证和运行,因此我们会收到交易哈希,因此无法将其用于我们的Web应用程序,但是我们可以发出呼叫而不是交易来轻松检查结果。

In a real system we would expect the manufacturer to provide the part hash with the physical part, but we won’t think about this mechanism here. We know the information used to generate the hash, so we can calculate it when we need, and that is exactly what we do on the testing code and also on the web app.

在真实的系统中,我们希望制造商将零件哈希与实际零件一起提供,但是在这里我们不会考虑这种机制。 我们知道用于生成哈希的信息,因此我们可以在需要时进行计算,这正是我们在测试代码和Web应用程序上所做的工作。

We won’t cover the test code so that we don’t extend the article, but check it out in our repository!

我们不会覆盖测试代码,因此我们不会扩展本文,而是在我们的存储库中进行检查!

The buildProduct method is just an extension of the buildPart method, adding a simple check to guarantee that all the parts were registered before attempting to create the product.

buildProduct方法只是buildPart方法的扩展,添加了一个简单的检查以确保在尝试创建产品之前已注册了所有部件。

Two things are really worth noting about the code:

关于代码,确实有两点值得注意:

  • Solidity generates getters automatically for public mappings, so we don’t need to worry about that!

    Solidity会自动为公共映射生成吸气剂,因此我们不必为此担心!
  • But we need to worry when returning array values, exactly the case for our product parts. We have created a “getParts” function to address this need.

    但是我们在返回数组值时需要担心,这正是我们产品零件的情况。 我们创建了一个“ getParts”函数来解决这一需求。

Continuing our development we will code the “ChangeOwnership” contract. It has a simple purpose: manage the part and product transfer between interested parties.

继续我们的发展,我们将编写“ ChangeOwnership”合同。 它的目的很简单:管理相关方之间的零件和产品转移。

Since we will use IDs on the ownership transfer operation, we can have one method for manufacturers to register their “initial ownership” and another method to change the ownership to other parties.

由于我们将在所有权转移操作中使用ID,因此,制造商可以采用一种方法来注册其“初始所有权”,而可以采用另一种方法将所有权更改为其他方。

We just need to receive a parameter to tell us if we want to register parts or products to know which mapping to check on the “ProductManagement” contract and also where to store the current item owner. The code is the following:

我们只需要接收一个参数来告诉我们是否要注册零件或产品,以了解要检查“ ProductManagement”合同上的哪个映射以及当前项目所有者的存储位置。 代码如下:

We use a “ProductManagement” instance to query for parts and products whenever we try to interact with them. This highlights an important aspect of smart contracts: you can use them to call other smart contracts! One option to do that is to declare the contract ABI on the beginning of the contract file, but just the parts required by your contract. In our case it means:

每当我们尝试与零件和产品进行交互时,我们都会使用“ ProductManagement”实例来查询它们。 这突出了智能合约的一个重要方面:您可以使用它们来调用其他智能合约! 一种选择是在合同文件的开头声明合同ABI,但仅声明合同所需的部分。 对我们而言,这意味着:

To point to the correct contract, we just need to pass the contract address when instantiating it, like this:

为了指向正确的合同,我们只需要在实例化时传递合同地址即可,如下所示:

pm = ProductManagement(prod_contract_add);

pm = ProductManagement(prod_contract_add);

Proceeding on the “ChangeOwnership” code review, we can also see that we define two events, TransferPartOwnership and TransferProductOwnership. Events can be logged with transactions, so that will the core of our “tracking” functionality.

继续进行“ ChangeOwnership”代码检查,我们还可以看到我们定义了两个事件,TransferPartOwnership和TransferProductOwnership。 可以使用事务记录事件,因此这将成为我们“跟踪”功能的核心。

Whenever a part or product is successfully transferred to another account, we will emit an event.

每当零件或产品成功转移到另一个帐户时,我们都会发出一个事件。

Take the addOwnership function as an example: we verify that the item exists, check if it is still unregistered and that the manufacturer is the one asking ownership. If we verify all that, we then store the manufacturer as the part owner and record that on Ethereum as an event. Later, we can query events about that part from its hash and see all the transfers.

以addOwnership函数为例:我们验证该物品是否存在,检查它是否仍未注册,并且制造商是要求所有权的人。 如果我们全部核实,则将制造商存储为零件所有者,并将其记录在以太坊上作为事件。 稍后,我们可以从其哈希查询有关该部分的事件,并查看所有传输。

The only other point to note about this code is on the function “changeOwnership”: whenever a car changes the owner we also change the ownership of the parts that compose it. But enough about code review, let’s check how to deploy it.

关于此代码的唯一要注意的一点是“ changeOwnership”功能:每当汽车更改所有者时,我们也会更改组成它的零件的所有权。 但是关于代码审查已经足够了,让我们检查如何部署它。

合同部署 (Contract Deployment)

To migrate our contracts to Ethereum we need to create a simple deployment file on the “deployments” folder. We can base ourselves on the “1_initial_migration.js” file created by Truffle, so our code becomes:

要将合同迁移到以太坊,我们需要在“ deployments”文件夹中创建一个简单的部署文件。 我们可以基于Truffle创建的“ 1_initial_migration.js”文件,因此我们的代码变为:

We can finally deploy our code to our local Ethereum network by running:

我们最终可以通过运行以下代码将代码部署到我们的本地以太坊网络:

truffle migrate -network development

truffle migrate -network development

When running that you will probably note that the ganache-cli terminal outputs a lot of messages, including some like:

运行该命令时,您可能会注意到ganache-cli终端会输出很多消息,其中包括:

Transaction: 0x9fe6d2ece9cdca2f12b574ead7abb7bea7feab316f5cd6ebbd5b713e76850a1dContract created: 0xb6a3c3cf9d1e27e43e5fb12e505d79764748edbe

Those represent our contract addresses, so save them to be able to communicate later. We will need this address on our web interface!

这些代表我们的合同地址,因此请保存下来以便以后沟通。 我们将在Web界面上需要此地址!

Web界面动手 (Web interface Hands On)

Our system now has both smart contracts ready and all we need is the interface to use them.

我们的系统现在已经准备好了智能合约,我们需要的只是使用它们的界面。

We made a page for each role on our scenario, so we have a “Part Factory View”, a “Car Factory View” and a “Dealer View”. We won’t get into the specifics of the methods implemented for the interactions, but let’s give an overview to instigate you to check the code!

我们为场景中的每个角色创建了一个页面,因此我们具有“零件工厂视图”,“汽车工厂视图”和“经销商视图”。 我们不会详细介绍为交互实现的方法,但让我们概述一下以鼓励您检查代码!

The part factory interactions, like part registration, ownership addition and ownership transfer, can be performed on the interface shown below. It is interesting to note Metamask asking for permission for every single transaction we make.

零件工厂交互,例如零件注册,所有权添加和所有权转移,可以在下面显示的界面上执行。 有趣的是,注意到Metamask要求我们进行的每笔交易都获得许可。

Looking at things from a car manufacturer’s perspective, we have the part list populated from the records on the blockchain, then the part selection to assemble the car, the car build, and finally we transfer the ownership to a dealer. Just like a part factory, the car factory also has its own interface, shown below. All interactions with Ethereum use the part/car hash created from their properties.

从汽车制造商的角度来看事情,我们从区块链上的记录中填充零件清单,然后选择零件以组装汽车,制造汽车,最后将所有权转让给经销商。 就像零件工厂一样,汽车工厂也有自己的界面,如下所示。 与以太坊的所有交互都使用从其属性创建的零件/汽车哈希。

The final view is from dealers, and for our example that is the simplest: we can just check the cars and parts for the owner history. Check the image below for details:

最终的意见来自经销商,对于我们的示例来说,这是最简单的:我们只需要检查汽车和零件的所有者历史即可。 检查下面的图像以获取详细信息:

Under the hood, we use the web3 library to call our smart contracts’ methods. The library provides us with objects representing our contracts and methods, and for that we only need to set:

在后台,我们使用web3库来调用智能合约的方法。 该库为我们提供了代表我们的合同和方法的对象,为此,我们只需要设置:

  • Network location

    网络位置
  • Contract ABI (smart contract definition)

    合同ABI(智能合同定义)
  • Contract address

    合约地址
  • Wallet to use for operations

    用于操作的钱包

By default, ganache-cli runs the network on the 8545 port and the ABI is generated every time you compile and deploy your contracts (but only when we update the code, so we don’t need to change that).

默认情况下,ganache-cli在8545端口上运行网络,并且每次您编译和部署合同时都会生成ABI(但仅在我们更新代码时才需要更改)。

If you ever need to, get the value stored on the “build” folder of the setup.The contract address we must specify with the values saved before, so change the following lines to your values:

如果需要,请获取存储在设置的“ build”文件夹中的值。我们必须使用之前保存的值指定合同地址,因此将以下几行更改为您的值:

Now that we have our page ready to interact with our smart contracts, we just need to prepare the functions that use the objects provided by web3 and our system is complete!

现在我们已经准备好与智能合约进行交互的页面,我们只需要准备使用web3提供的对象的功能,我们的系统就完成了!

The functions basically get the data from the input fields on the page and then call the functions with them as parameters. The complete code is too big to fit this article, but let’s check just two parts that explain most of the interactions with the blockchain. The first is:

这些函数基本上是从页面上的输入字段中获取数据,然后使用它们作为参数来调用这些函数。 完整的代码太大了,无法满足本文的要求,但是让我们仅检查两个部分来解释与区块链的大多数交互。 第一个是:

The “window.co” object is our “ChangeOwnership” contract, and both currentPartOwner and addOwnership are methods provided by it.The difference here is on the function used to call them: call vs send.Web3 1.0 requires you to specify the type of interaction that you want to do with the blockchain: reads or transactions.

“ window.co”对象是我们的“ ChangeOwnership”合同,currentPartOwner和addOwnership都是它提供的方法。这里的区别在于用于调用它们的函数:call vs send.Web3 1.0要求您指定您想与区块链进行的交互:读取或交易。

So whenever you use a method with “call” you are just reading data from the blockchain, it costs you no ether and also does not change the chain state.

因此,每当您使用一种带有“调用”的方法时,您只是从区块链中读取数据,就不会花费任何以太币,也不会改变链状态。

On the other hand, if you use “send” you have to send gas to perform the operation and it creates a transaction. As we have said before, transactions are not mined immediately, so take that into account when developing real world Dapps.

另一方面,如果您使用“发送”,则必须发送气体以执行该操作并创建交易。 如前所述,交易不会立即进行,因此在开发实际的Dapps时要考虑到这一点。

Finally, the second part to be highlighted is:

最后,要强调的第二部分是:

Remember when we said that Events would be our supply chain core? This line is used to get all events from a specific type, filtering the results by the part hash.

还记得我们说活动将是我们的供应链核心吗? 该行用于获取特定类型的所有事件,并按零件哈希过滤结果。

It means that we can get everything that happened with a single part, and if we want we can also get the part details using the same hash and calling “parts” from “ProductManagement”.

这意味着我们可以获得单个零件的所有信息,如果需要,我们还可以使用相同的哈希并从“ ProductManagement”中调用“ parts”来获取零件详细信息。

Pretty cool, huh?

太酷了吧?

结语 (Wrapping Up)

And we’re done!

我们完成了!

Every time a part manufacturer wants to notify a new part production, a car manufacturer wants to assemble that in a car, or we want to move the parts and cars from one owner to another, we can simply use the web interface to do it.

每当零件制造商想要通知新的零件生产,汽车制造商想要在汽车中组装零件,或者我们想将零件和汽车从一个所有者转移到另一个所有者时,我们只需使用Web界面即可完成。

We have a transparent record that allows manufacturers, dealers and buyers to have the same information about the products.

我们有一个透明的记录,使制造商,经销商和购买者可以获得有关产品的相同信息。

If a problem is found about a certain serial number range in the factories, the factory can check where to tackle and solve the problem.

如果在工厂中发现有关某个序列号范围的问题,则工厂可以检查在哪里解决并解决该问题。

The same is true in the opposite direction: dealers and buyers can trace back their products’ parts to the factories in case they have problems or need replacements.

相反的方向也是如此:经销商和买家可以将他们的产品零件追溯到工厂,以防他们遇到问题或需要更换。

Implementing the system based on a blockchain also provides a distributed and consistent record that none of the participants can alter without traces, so we avoid foul play.

基于区块链的系统实施还提供了分布式且一致的记录,任何参与者都无法更改而不会留下任何痕迹,因此我们避免了犯规行为。

We have simplified the supply chain scenario a lot, but we hope that this demo has shown the power of using the blockchain in this context. Now you can start your solution planning and consider it as an implementation alternative.

我们已经大大简化了供应链方案,但是我们希望这个演示展示了在这种情况下使用区块链的力量。 现在,您可以开始解决方案计划,并将其视为替代方案。

I hope you enjoyed it!

我希望你喜欢它!

翻译自: https://www.freecodecamp.org/news/how-to-build-a-car-manufacturing-supply-chain-system-using-ethereum-cbb87144cde5/

以太坊公链私链

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值