Ethereum is now one of the most popular platforms for creating decentralized applications, which is actively developing. One of the innovations of Zeppelin we will try today with our own hands. And for those who are in the "tank", Zeppelin is a company that develops and verifies the security of smart contracts. The smart contract library OpenZeppelin is their most famous product.
It turned out that the development tools for Solidity are still evolving, sometimes not allowing developers to use the full power of smart contract technology. For example, the limitation is “standard libraries”, since each time an existing code is reloaded onto the network, which leads to an increase in the cost of “deploying” code and the number of potential errors. All this leads to significant limitations in creating large and multifunctional decentralized applications.
Zeppelin OS is an open source platform consisting of tools and services over EVM, designed to develop and manage decentralized applications.
The Zeppelin team identified the four most important components, some of which are already implemented and available for use.
I really wanted to start working with Zeppelin OS, write the first contract and update it. Check whether everything is in fact and not deceived by the developers.
Therefore, leaving the device updated storage and proxies for future articles, we move on to the already implemented functionality.
All Zeppelin OS documentation can be found here . First you need to install zos:
$ npm install --global zos
Now create a project directory and everything you need for it:
$ mkdir zostest && cd zostest $ npm init $ zos init zostest
After that, all the necessary configuration files will be created, so now you can proceed to writing contracts. As a test contract, let's write a small "variable repository":
pragma solidity 0.4.24; import "zos-lib/contracts/migrations/Migratable.sol"; contract SimpleStorage is Migratable { uint storedData; function initialize(uint256 _x) isInitializer("SimpleStorage", "0") public { storedData = _x; } function get() public constant returns (uint) { return storedData; } }
Compile and add our contract:
$ zos add SimpleStorage
We start a test network (in a separate terminal):
$ npx ganache-cli --port 9545
Push into our local network, this creates a new configuration file zos.local.json
:
$ zos push --network local
Things are going well, it remains to create our updatable contract, simultaneously run initialize()
with argument 88 for our “repository”:
$ zos create SimpleStorage --init initialize --args 88 --network local
Now we will try to add the function of increasing the variable in the “storage”, for example, the following:
pragma solidity 0.4.24; import "zos-lib/contracts/migrations/Migratable.sol"; contract SimpleStorage is Migratable { uint storedData; function initialize(uint256 _x) isInitializer("SimpleStorage", "0") public { storedData = _x; } function incrementStorage(uint256 _x) public { storedData += _x; } function get() public constant returns (uint) { return storedData; } }
After that, you need to update the contract on the network:
$ zos push --network local
$ zos update SimpleStorage --network local
Now you can see what happened. For this we use the truffle console
:
$ npx truffle console --network=local truffle(local)> sS = SimpleStorage.at(<proxy-address>)
And <proxy-address>
you can see in the corresponding column in zos.local.json
, and check that we have it in the “repository” and whether we can increase the variable:
Everything works great, there are many opportunities for testing contracts. I would say that Zeppelin OS can be used as a development tool for sure.
We have verified that using Zeppelin OS you can deploy, update, compile and test contracts. It seems to be a great tool for those who like to work with the command line, and from Remix in the browser shudders. Plus, we can recommend starting acquaintance with Solidity and smart contracts with this project.
Source: https://habr.com/ru/post/424801/