Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

docs: restructure the docs website #305

Merged
merged 46 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3fc5ba1
[CI skip] First draft of a new section describing the unstructured st…
eternauta1337 Oct 17, 2018
72778e2
[CI skip] Finished first draft of Proxy section.
eternauta1337 Oct 18, 2018
f80ade0
[CI skip] Merged some items in advanced.md to proxies.md
eternauta1337 Oct 18, 2018
d7c1bcb
[CI skip] Assimilated some of elopio's reviews
eternauta1337 Oct 18, 2018
253cdcb
[CI skip] Minor spelling fixes
eternauta1337 Oct 18, 2018
e2f6c63
[CI skip] Added a few diagrams to the proxies section.
eternauta1337 Oct 18, 2018
b67fba3
Modified advanced section about json files to account for light mode.
eternauta1337 Oct 10, 2018
c8e19af
Removed (or names!)
eternauta1337 Oct 11, 2018
5a851e7
[CI skip] updated advanced section, jsons sub-section about the --ful…
eternauta1337 Oct 12, 2018
544da16
[CI skip] Typo fix explicitely > explicitly
eternauta1337 Oct 16, 2018
9cec3da
Update dependencies version on push (#279)
spalladino Oct 17, 2018
75a81b4
Reupload contract if related lib has changed (#280)
spalladino Oct 17, 2018
a3f6c15
Use version of dependency for identifying proxies in network json fil…
spalladino Oct 17, 2018
8e62210
Add vouching kovan deploy
facuspagnuolo Oct 17, 2018
308492b
Link command now successfully runs npm install again (#278)
spalladino Oct 17, 2018
b8726b5
Check if project is published before freeze (#285)
jbcarpanelli Oct 17, 2018
013ec76
docs: remove basil and crafty demos (#277)
Oct 17, 2018
d92259c
Stdlib/lib/dependency rename to package (#240)
jbcarpanelli Oct 17, 2018
c6ef507
Fix storage layout parsing when there are complex types (#286)
spalladino Oct 17, 2018
f182aa1
Change status fix/fetch error message (#289)
jbcarpanelli Oct 18, 2018
403db54
Preserve error stack trace when using ScriptError (#287)
jbcarpanelli Oct 18, 2018
792bfe2
Update and unify package json files structures (#282)
facuspagnuolo Oct 18, 2018
9879791
Check if package is frozen before uploading solidity libs (#284)
spalladino Oct 18, 2018
7084940
Cleanup the READMEs (#276)
Oct 18, 2018
1007a8e
Fix docs readme clone instructions
facuspagnuolo Oct 18, 2018
bfd4b5b
Update to v2.0.0-rc.0
spalladino Oct 18, 2018
1da6c84
Update CLI package lock
facuspagnuolo Oct 18, 2018
f688838
Use latest versions of TPL-eth and OZ-eth (#295)
facuspagnuolo Oct 18, 2018
fb3ecca
Update to v2.0.0
spalladino Oct 18, 2018
15421f7
Fix vouching deployment script
facuspagnuolo Oct 18, 2018
d77ae32
Update CLI package lock
facuspagnuolo Oct 18, 2018
4e1ffbe
Update TPL-eth and OZ-eth to latest released versions
facuspagnuolo Oct 18, 2018
84a5e56
Add zos files to vouching package files list
facuspagnuolo Oct 18, 2018
78eabe8
Applied @facuspagnuolo's suggestion about publish
come-maiz Oct 19, 2018
bfc7c9a
docs: restructure the docs webiste
come-maiz Oct 19, 2018
76b6b91
Merge branch 'master' into docs/restructure
come-maiz Oct 19, 2018
a7bfb8e
Merge branch 'master' into docs/restructure
come-maiz Oct 22, 2018
565bbcd
Merge branch 'master' into docs/restructure
come-maiz Oct 22, 2018
05a2ca4
Merge branch 'master' into docs/restructure
come-maiz Oct 22, 2018
3773252
Remove the duplicated proxies
come-maiz Oct 22, 2018
7cbad94
Fix the new in zOS 2 page.
come-maiz Oct 23, 2018
11c1230
[CI skip]
come-maiz Oct 23, 2018
67da808
correction for consistency
come-maiz Oct 23, 2018
b39c89d
fix small mistakes
come-maiz Oct 23, 2018
c4ae833
fix small mistakes
come-maiz Oct 23, 2018
f02f0eb
Merge branch 'master' into docs/restructure
come-maiz Oct 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ push these contracts to a blockchain network with `zos push`, use
`zos create` to create instances for these contracts that later can be
upgraded, and many more things.

Run `zos --help` for more details about thes and all the other functions of
Run `zos --help` for more details about this and all the other functions of
ZeppelinOS.

The
Expand Down
113 changes: 0 additions & 113 deletions packages/docs/docs/docs/building.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,119 +1,12 @@
---
id: advanced
title: Advanced topics
id: configuration
title: Configuration Files
---

We expand on several advanced topics for the more intrepid users of ZeppelinOS.

## Deploying to mainnet
The [Building upgradeable applications](building.md) guide explains how to
deploy an application to a local network, which is very good for testing.
Once you are happy with your initial contracts, you can deploy them to mainnet
using the `--network` flag.

This flag takes the network details from the Truffle configuration file. You
can use Infura to connect to mainnet, with a `truffle-config.js` like this one:

```
'use strict';

var HDWalletProvider = require("truffle-hdwallet-provider");

var mnemonic = "orange apple banana ... ";

module.exports = {
networks: {
mainnet: {
provider: function() {
return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/<INFURA_Access_Token>")
},
network_id: 1
}
}
};
```

Make sure to replace the `mnemonic` with the one you used to generate your
accounts, and change `<INFURA_Access_Token>` to your token.

Install the `truffle-hdwallet-provider` module with:

```
npm install truffle-hdwallet-provider
```

And now you can run `zos` commands in mainnet. For example:

```
zos push --network mainnet
```

This will use your first account generated from the mnemonic. If you want to
specify a different account, use the `--from` flag.

Here you will find a
[guide with more details about configuring Truffle to use Infura](http://truffleframework.com/tutorials/using-infura-custom-provider).
You can use other test networks like ropsten to further test your contracts
before pushing them to mainnet. But remember that now your contracts are
upgradeable! Even if you find a bug after deploying them to mainnet, you will
be able to fix it without losing the contract state and in a way that's
transparent for your users.

#### Calling Initialize Functions Manually in Your Unit Tests

Truffle does not know how to resolve situations where a contract has functions that have matching names, but different arities. Here's an example of a `TimedCrowdsale` contract that inherits from `Crowdsale` which results in a contract that has two `initialize` functions with different arities:

```
contract TimedCrowdsale is Crowdsale {

initialize(uint256 _openingTime, uint256 _closingTime)
public
isInitializer("TimedCrowdsale", "0.0.1")
{
Crowdsale.initialize(_rate, _wallet, _token);
}
}

contract Crowdsale {

initialize(uint256 _rate, address _wallet, ERC20 _token)
public
isInitializer("Crowdsale", "0.0.1")
{
// does something
}
}
```

This means that calls to contracts with more than one function named `initialize`, as is the case with some contracts from OpenZeppelin (e.g., TimedCrowdsale), may revert if you call `initialize` directly from Truffle. `zos create` handles this correctly as it encodes the parameters. However, for your unit tests you will need to call `initialize` manually.

The current solution to this issue is to `npm install zos-lib` and use the same helper function `zos create` uses: `encodeCall`. `encodeCall` receives the signature of your `initialize` function, as well as its arguments and their types. It then crafts the calldata which you can send in a raw call. Here's an example:

```
data = encodeCall(
"initialize",
['address', 'string', 'string', 'uint8', 'address'],
[owner, name, symbol, decimals, exampleToken.address]
);

await exampleToken.sendTransaction( {data, from: owner} );
```
## Safety checks

The ZeppelinOS CLI performs a series of safety checks in some of its commands with the purpose of strengthening the security of your projects. For example, the `zos add` command can detect if a contract has a `constructor`, or contains usages of `selfdestruct` or `delegatecall`. Below is a list of some of the checks made, along with the reasoning behind why they are considered to be security risks.

**Some validation examples:**
* constructor check: Proxied contracts should use initializer functions instead of constructors. For more info, see [Initializers vs. constructors](https://docs.zeppelinos.org/docs/advanced.html#initializers-vs-constructors) in this page.
* selfdestruct check: Solidity's `selfdestruct` keyword ends the execution of a contract, destroys it, and sends all of its funds to a specified account. This is a very delicate action to take, and can expose a contract to vulnerabilities such as the [second Parity Wallet hack](https://blog.zeppelinos.org/parity-wallet-hack-reloaded/). It should be used with extreme care.
* delegatecall check: The `delegatecall` keyword fully exposes a contract's state to a 3rd party contract. Such a contract has complete control on the calling contract. It should only be used if you really know [hat you're doing.

When such validation checks fail, the ZeppelinOS CLI will not performs any actions unless the `--force` option is used. If so, the CLI will perform the actions and try to remember your choice in future occasions.

## Format of `zos.json` and `zos.<network>.json` files
ZeppelinOS's CLI generates `json` files where it stores the configuration of your project.


### `zos.json`
## `zos.json`
The first file stores the general configuration and is created by the `zos init` command. It has the following structure:

```json
Expand All @@ -132,10 +25,10 @@ The first file stores the general configuration and is created by the `zos init`
}
```

Here, `<projectName>` is the name of the project, and `<version>` is the current version number. Once you start adding your contracts via `zos add`, they will be recorded under the `"contracts"` field, with the contract aliases as the keys (which default to the contract names), and the contract names as the values. Finally, if you link an `stdlib` with `zos link`, this will be reflected in the `"stdlib"` field, where `<stdlibName>` is the name of the linked `EVM package`.
Here, `<projectName>` is the name of the project, and `<version>` is the current version number. Once you start adding your contracts via `zos add`, they will be recorded under the `"contracts"` field, with the contract aliases as the keys (which default to the contract names), and the contract names as the values. Finally, if you link an `stdlib` with `zos link`, this will be reflected in the `"stdlib"` field, where `<stdlibName>` is the name of the linked `EVM Package`.


### `zos.<network>.json`
## `zos.<network>.json`
ZeppelinOS will also generate a file for each of the networks you work on (`local`, `ropsten`, `live`, ... These should be configured [in your `truffle.js` file](http://truffleframework.com/docs/advanced/configuration#networks), but note that `zos init` already configures the `local` network, which can be run by `npx truffle develop`). These files share the same structure:

```json
Expand Down Expand Up @@ -203,4 +96,5 @@ Another thing to notice in these files are the version numbers. The `<appVersion

Also, notice the fields `<app>` and `<package>`. These contain the addresses of contracts that ZeppelinOS uses to facilitate the creation of proxies and the management of different versions of your contracts. These contracts will only be deployed once you publish your project to a desired network. That is, your project will not have an `app` or `package` unless explicitly running the `publish` command. Note that this step is required for projects that produce an EVM package. To read more about the architecture of contracts we are using to publish your project on-chain please refer to the [Contract Architecture](https://docs.zeppelinos.org/docs/architecture.html) section.


Finally, the `stdlib` field stores information about linked EVM packages. Its address is stored in `<stdlib-address>`, and its name in `<stdlib-name>`, matching that in `zos.json`. The `custom-deploy` field will be present only when a version of the EVM package is deployed using the `--deploy-libs` flag of the `push` command, in which case `<custom-deploy>` will be `true`. The remaining addresses, `<app-address>`, `<package-address>`, and `<provider-address>` store the addresses of the `App`, the `Package`, and the current `ImplementationProvider` respectively.
129 changes: 129 additions & 0 deletions packages/docs/docs/docs/deploying.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
id: deploying
title: Deploying your first project
---

The following steps will get you started using ZeppelinOS.

## Installation

Let's install [Node.js](http://nodejs.org/) and
[npm](https://npmjs.com/), which are the dependencies to get started. On their
respective websites you will find specific instructions for your machine.

Then, install ZeppelinOS running:

```sh
npm install --global zos
```

Run `zos --help` to get a list of all the ZeppelinOS commands. At any time
during this guides when we introduce a new command, run
`zos <command-name> --help` to get more information about that command and
its arguments.

## Setting up your project

We'll need to create a directory for our project and access it:

```sh
mkdir my-project
cd my-project
```

Use `npm` to create a `package.json` file:

```sh
npm init
```

This command will ask you for details about the project. For this very basic
guide you can just press enter to accept the default values of each field.

Now, we can initialize the ZeppelinOS project:

```
zos init my-project
```

This command will create a `zos.json` file, which contains all the information
about the project. For details about this file format, please see the
[configuration files](configuration.md#zosjson) page.

The command will also initialize [Truffle](https://truffleframework.com/), so
by now, inside the `my-project` directory you should have a `package.json` file
(create by `npm`), two empty directories named `contracts` and `migrations` and
a file `truffle-config.js` (created by `zos` for Truffle), and a file
`zos.json` (created by `zos` for ZeppelinOS).

## Adding a contract

Let's create a very simple contract as an example to be added to the project.
Name it `MyContract.sol`, and put it in the `contracts/` folder with the
following Solidity code:

```sol
pragma solidity ^0.4.24;

import "zos-lib/contracts/Initializable.sol";

contract MyContract is Initializable {

uint256 public x;

function initialize(uint256 _x) initializer public {
x = _x;
}
}
```

Notice that our sample contract has an `initialize` function instead of the
standard Solidity constructor. This is required by ZeppelinOS if you want to
upgrade your contract later, which we'll see in more detail in the next
guide.

But before we get there, we still need a couple of steps. This contract
imports another contract from the `zos-lib` package, so we have to install it:

```
npm install zos-lib
```

Now we can add the contract to the project:

```sh
zos add MyContract
```

This command will first compile `MyContract`, and then it will add it to the
project writing it in the `zos.json` configuration file.

## Deploying your project

And just like that, we are now ready to make the initial deployment of the
project. We are just missing a blockchain network where it will be deployed.
For this example, let's use Truffle's local development network. To start it,
open a separate terminal and run:

```sh
truffle develop --network local
```

And back in the original terminal:

```sh
NODE_ENV=test zos push --network local
```

This creates a `zos.local.json` file with all the information about your
project in this specific network. You can read more about this file format
in the [configuration files](configuration.md#zos-network-json) section.

You can follow the same steps to deploy your project to mainnet or other test
networks by just replacing `local` with the network name from your
`truffle-config.js` file, and removing the `NODE_ENV=test` flag. This is
further explained in the [Deploying to mainnet](mainnet) guide.

But for now, let's continue exploring the ZeppelinOS features! The initial
version of our project exists in the blockchain. Next, we will learn how to
upgrade it.
Loading