Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Buidler Tutorial for beginners #483

Merged
merged 38 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e585969
Remove development branch warning
alcuadrado Feb 27, 2020
a3f6269
[docs] Update quick start with console.log mention
fzeoli Feb 28, 2020
85e1eac
Add tutorial.md
Mar 25, 2020
2a0ceff
Tutorial layout with custom sidebar
Mar 25, 2020
511af8e
Some progress
Apr 3, 2020
a1f21f9
Add Guidelines to the sidebar
Apr 3, 2020
f6df161
[docs] Add debug, deploy and frontend sections
Apr 7, 2020
d1f6004
[docs] Some changes regarding @fzeoli feedback
Apr 7, 2020
4283682
[docs] Yet another iteration
Apr 7, 2020
187757f
[docs] Add Final Thoughts section
Apr 7, 2020
96f959d
[docs] Remove Guidelines section
Apr 7, 2020
e83bdad
[docs] Yet another iteration
Apr 8, 2020
6fb5993
[docs] Yet another iteration
Apr 8, 2020
a023027
[docs] polish the setup section of the tutorial
fzeoli Apr 8, 2020
453aebe
[docs] Polish tut setup, install & config sections
fzeoli Apr 10, 2020
2759140
[docs] Add plugin deps mention in tut config section
fzeoli Apr 10, 2020
66a0c90
[docs] Add mention of node-gyp to env setup in tutorial
fzeoli Apr 11, 2020
302dbc9
[docs] Polish contracts section of tutorial
fzeoli Apr 11, 2020
7dcbfe6
[docs] Polish testing section of the tutorial
fzeoli Apr 11, 2020
eacadcb
[docs] Swap getAddress for balanceOf in testing tuto
fzeoli Apr 13, 2020
686929b
[docs] Polish tuto's debugging section
fzeoli Apr 13, 2020
82c8750
[docs] Polish deploy section of tuto
fzeoli Apr 13, 2020
9047953
[docs] Change title of deployment section of tutorial
fzeoli Apr 13, 2020
19e9864
[docs] Polish overview and install sections of tutorial
fzeoli Apr 13, 2020
26bd417
[docs] Clarify not an ERC20 in contracts section of tutorial
fzeoli Apr 13, 2020
a283823
[docs] Add more content to the tutorial's overview
fzeoli Apr 15, 2020
4deec4e
[tutorial] Merge create and install sections
fzeoli Apr 15, 2020
f6e5042
[tutorial] Add additional information to the overview
fzeoli Apr 15, 2020
8346f57
[tutorial] Replace frontend section with boilerplate section.
fzeoli Apr 15, 2020
9a9c1b8
[tutorial] Fix a link and polish final thoughts
fzeoli Apr 17, 2020
f944c37
[tutorial] Add network setup guide for deployment
fzeoli Apr 17, 2020
26096b8
Update the code from tutorial/4-contracts
alcuadrado Apr 17, 2020
fc9b903
Update tests code
alcuadrado Apr 17, 2020
c20b495
Update deploy section
alcuadrado Apr 17, 2020
7923a87
Update deploy section
alcuadrado Apr 17, 2020
13a75ec
[docs] Fix setup url and broken link to next step
Apr 17, 2020
4246060
[tutorial] Fix broxen link
viarnes Apr 17, 2020
8701014
Merge branch 'development' into tutorial
alcuadrado Apr 18, 2020
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
126 changes: 75 additions & 51 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
{ text: "Buidler EVM", link: "/buidler-evm/" },
{ text: "Plugins", link: "/plugins/" },
{ text: "Documentation", link: "/getting-started/" },
{ text: "Tutorial", link: "/tutorial/" },
{ text: "API", link: "/api/" }
],
lastUpdated: true,
Expand All @@ -32,57 +33,80 @@ module.exports = {
editLinks: true,
sidebarDepth: 1,
displayAllHeaders: true,
sidebar: [
["/getting-started/", "Getting Started", 1],
["/config/", "Configuration", 0],
["/buidler-evm/", "Buidler EVM", 0],
{
title: "Guides",
url: "/guides/",
collapsable: false,
depth: 1,
children: [
["/guides/truffle-migration.md", "Migrating from Truffle", 0],
["/guides/project-setup.md", "Setting up a project", 0],
["/guides/compile-contracts.md", "Compiling your contracts", 0],
["/guides/truffle-testing.md", "Testing with Web3.js & Truffle", 0],
["/guides/waffle-testing.md", "Testing with ethers.js & Waffle", 0],
["/guides/deploying.md", "Deploying your contracts", 0],
["/guides/scripts.md", "Writing scripts", 0],
["/guides/buidler-console.md", "Using the Buidler console", 0],
["/guides/create-task.md", "Creating a task", 0],
["/guides/ganache-tests.md", "Running tests with Ganache", 0],
["/guides/vscode-tests.md", "Running tests on VS Code", 0],
["/guides/typescript.md", "TypeScript support", 0]
]
},
{
title: "Advanced",
collapsable: false,
children: [
[
"/advanced/buidler-runtime-environment.html",
"Buidler Runtime Environment (BRE)",
0
],
["/advanced/building-plugins.html", "Building plugins", 0]
]
},
{
title: "Troubleshooting",
collapsable: false,
children: [
["/troubleshooting/verbose-logging.html", "Verbose logging", 0],
["/troubleshooting/common-problems.html", "Common problems", 0],
["/errors/", "Error codes", 0]
]
},
{
title: "Plugins",
collapsable: false,
children: pluginsChildren
}
]
sidebar: {
'/tutorial/': [
["", "Overview", 1],
["0-guidelines/", "Guidelines", 0],
{
title: "Tutorial",
url: "1-setup/",
collapsable: false,
depth: 1,
children: [
["1-setup/", "1. Setting up the environment", 0],
["2-install/", "2. Installing Buidler", 0],
["3-config/", "3. Configuring Buidler", 0],
["4-contracts/", "4. Creating and compiling contracts", 0],
["5-test/", "5. Testing contracts", 0],
["6-debug/", "6. Debugging contracts with Buidler EVM", 0],
["7-frontend/", "7. Creating a frontend", 0],
["8-deploy/", "8. Deploying contracts", 0],
["9-final-thoughts/", "9. Final thoughts", 0],
]
},
],
'/': [
["/getting-started/", "Getting Started", 1],
["/config/", "Configuration", 0],
["/buidler-evm/", "Buidler EVM", 0],
{
title: "Guides",
url: "/guides/",
collapsable: false,
depth: 1,
children: [
["/guides/truffle-migration.md", "Migrating from Truffle", 0],
["/guides/project-setup.md", "Setting up a project", 0],
["/guides/compile-contracts.md", "Compiling your contracts", 0],
["/guides/truffle-testing.md", "Testing with Web3.js & Truffle", 0],
["/guides/waffle-testing.md", "Testing with ethers.js & Waffle", 0],
["/guides/deploying.md", "Deploying your contracts", 0],
["/guides/scripts.md", "Writing scripts", 0],
["/guides/buidler-console.md", "Using the Buidler console", 0],
["/guides/create-task.md", "Creating a task", 0],
["/guides/ganache-tests.md", "Running tests with Ganache", 0],
["/guides/vscode-tests.md", "Running tests on VS Code", 0],
["/guides/typescript.md", "TypeScript support", 0]
]
},
{
title: "Advanced",
collapsable: false,
children: [
[
"/advanced/buidler-runtime-environment.html",
"Buidler Runtime Environment (BRE)",
0
],
["/advanced/building-plugins.html", "Building plugins", 0]
]
},
{
title: "Troubleshooting",
collapsable: false,
children: [
["/troubleshooting/verbose-logging.html", "Verbose logging", 0],
["/troubleshooting/common-problems.html", "Common problems", 0],
["/errors/", "Error codes", 0]
]
},
{
title: "Plugins",
collapsable: false,
children: pluginsChildren
}
]
}
},
head: [
[
Expand Down
2 changes: 1 addition & 1 deletion docs/buidler-evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ the in-process Buidler EVM provider. See [Buidler EVM's config](../config/README
Buidler EVM is initialized by default in this state:

- A brand new blockchain, just with the genesis block.
- 20 accounts with 10.000 ETH each
- 20 accounts with 10000 ETH each
- `0xc783df8a850f42e7f7e57013759c285caa701eb6`
- `0xead9c93b79ae7c1591b1fb5323bd777e86e150d4`
- `0xe5904695748fe4a84b40b3fc79de2277660bd1d3`
Expand Down
25 changes: 22 additions & 3 deletions docs/getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,28 @@ Next, if you take a look at `contracts/`, you should be able to find `Greeter.
```js
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";

contract Greeter {

string greeting;

constructor(string memory _greeting) public {
console.log("Deploying a Greeter with greeting:", _greeting);
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
greeting = _greeting;
}

}

```

To compile it, simply run:
Expand Down Expand Up @@ -195,13 +204,23 @@ You can run your tests with `npx buidler test`
```
$ npx buidler test
Compiling...
Compiled 1 contract successfully
Compiled 2 contracts successfully


Contract: Greeter
✓ Should return the new greeting once it's changed (323ms)
Deploying a Greeter with greeting: Hello, world!
Changing greeting from 'Hello, world!' to 'Hola, mundo!'
✓ Should return the new greeting once it's changed (344ms)

Greeter contract
Deployment
Deploying a Greeter with greeting: Hello, world!
Deploying a Greeter with greeting: Hola, mundo!
✓ Should deploy with the right greeting (82ms)


2 passing (434ms)

1 passing (323ms)
```

### Deploying your contracts
Expand Down
18 changes: 18 additions & 0 deletions docs/tutorial/0-guidelines/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Guidelines

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo animi nihil, quidem, fugit sit aut libero at nostrum mollitia dolorum aliquid quas dolores quae labore velit praesentium ratione accusantium autem nobis dignissimos error quo tempore ducimus veritatis. Sapiente, corporis dicta.

## How to follow a tutorial
Lorem ipsum dolor sit amet.

## JavaScript
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam voluptatibus at delectus accusamus, excepturi qui incidunt numquam vel nihil minus.

## Terminal
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam voluptatibus at delectus accusamus, excepturi qui incidunt numquam vel nihil minus.

## Git
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam voluptatibus at delectus accusamus, excepturi qui incidunt numquam vel nihil minus.

## Smart contracts
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam voluptatibus at delectus accusamus, excepturi qui incidunt numquam vel nihil minus.
102 changes: 102 additions & 0 deletions docs/tutorial/1-setup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
prev: false
---

# 1. Setting up the environment

First things first. Most Ethereum libraries and tools use Node.js and **Buidler** is no exception. In case you are not familiar with Node.js, you might think of it as "JavaScript running on your computer" — but it’s so much more as well. For now we are just installing it.

## Installing Node.js

This section has instructions for installing Node.js in the operating system of your choice. Feel free to skip any step you don't consider necessary.

::: tip
If you have Node.js `>=10.0` already installed, please skip to: [Checking your environment](#checking-your-environment).
:::

### Linux

#### Ubuntu

Copy and paste these commands in a terminal:

```
sudo apt update
sudo apt install curl git
sudo apt install build-essential # We need this to build native dependencies
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
fzeoli marked this conversation as resolved.
Show resolved Hide resolved
sudo apt install nodejs
```

### MacOS

Make sure you have `git` installed. Otherwise, follow [these instructions](https://www.atlassian.com/git/tutorials/install-git).

There are multiple ways of installing Node.js in MacOs, we will be using [Node Version Manager (nvm)](http://github.com/creationix/nvm). Copy and paste these commands in a terminal:

```
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
fzeoli marked this conversation as resolved.
Show resolved Hide resolved
nvm install 10
nvm use 10
nvm alias default 10
npm install npm --global # Upgrade npm to the latest version
npm install -g node-gyp # Make sure we have node-gyp installed

# This next setp is needed to build native dependencies.
# A popup will appear and you have to proceed with an installation.
# It will take some time, and may download a few GB of data.
xcode-select --install
```

### Windows

Installing Node.js on Windows requires some manual installations first. Please follow them.

1. If you don't have `git` installed, please [download and install it](https://git-scm.com/download/win).
2. Install Node.js 10.x by going to [its download page](https://nodejs.org/dist/latest-v10.x), downloading `node-v10.XX.XX-x64.msi`, and running it.
3. [Open your terminal as Administrator](https://www.howtogeek.com/194041/how-to-open-the-command-prompt-as-administrator-in-windows-8.1/) and run the following command: `npm install --global --production windows-build-tools`. It will take several minutes and may download a few GB of data.


## Checking your environment

To make sure your development environment is ready, copy and paste these commands in a new terminal:

```
git clone https://github.com/nomiclabs/ethereum-hackathon-setup-checker.git
cd ethereum-hackathon-setup-checker
npm install
```

If they went well, you should see a confirmation message meaning that your development environment is ready. Feel free to remove the repository and refer to the next step: [Installing Buidler.](../2-install/)

If any of them failed, your environment is not ready. Make sure to have `git` and Node.js `>=10.0` installed. If you have an older version of Node.js, please refer to the next section. If the issues persists, please contact us on our [Telegram Support Channel](https://t.me/BuidlerSupport).

## Upgrading your version of Node.js

If your version of Node.js is too old (`<10.0`) follow these instructions. After you are done, go back to [Checking your environment](#checking-your-environment).

### Linux

#### Ubuntu

1. Remove nodejs with `sudo apt remove nodejs`.
2. Go to the [NodeSource's Node.js Binary Distributions](https://github.com/nodesource/distributions#debinstall), and install their PPA for the version of Node.js that you are looking for.
3. Run `sudo apt update && sudo apt install nodejs`

### MacOS

You can change your Node.js version using [nvm](http://github.com/creationix/nvm).

For example, this is how you'd upgrade to Node.js 12.x:

```
nvm install 12
nvm use 12
nvm alias default 12
npm install npm --global # Upgrade npm to the latest version
npm install -g node-gyp # Make sure we have node-gyp installed
```

### Windows

You need to follow the same installation instructions but choosing [another version of Node.js from its website](https://nodejs.org/en/download/releases/).
23 changes: 23 additions & 0 deletions docs/tutorial/2-install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 2. Installing Buidler

We will install **Buidler** through `npm`. `npm` (Node Package Manager) is two things: first and foremost, it is an online repository for the publishing of open-source Node.js project such as **Buidler**; second, it is a command-line utility for interacting with said repository.

Open a new terminal, copy and paste these commands:

```
mkdir buidler-tutorial # Create a new folder
cd buidler-tutorial # Access the folder
npm init --yes # Initialize a new npm project
npm install --save-dev @nomiclabs/buidler # Install Buidler and dependencies
```

::: warning
**Buidler** package will also install all its dependencies, so it might take a while.
:::

## What is Buidler?
You might think of **Buidler** as a runtime environment designed around the concepts of tasks and plugins. This means interoperability and flexibility turning **Buidler** into the perfect toolkit for smart contract and dapp development.
fzeoli marked this conversation as resolved.
Show resolved Hide resolved

It also comes with **Buidler EVM**, a local Ethereum network that allows you to test, debug and deploy your contracts more quickly. You can even use `console.log` inside your Solidity code. And no, that was not possible before **Buidler EVM** :sunglasses:

When installation completes, go to step 3: [Configuring Buidler.](../3-config/)
Loading