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

[docs] Replace Truffle/web3 mentions and sample-project with Waffle/ehters #517

Merged
merged 23 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9822055
[docs] Replace Getting Started Truffle/web3 examples with Waffle/ehters
Apr 15, 2020
9e448e0
Modify sample project files to use Waffle/Ethers
Apr 15, 2020
ef543e1
Add node_modules to sample projects .gitignore
Apr 15, 2020
8fc6fed
Move node_modules outside 'Buidler Files' on sample projects .gitignore
Apr 16, 2020
433604b
[docs] Adapt guides/scripts to new sample project's sample-script.js
Apr 16, 2020
88a2001
[docs] Add --no-compile parameter to guides/scripts callout
Apr 16, 2020
2ae8407
[docs] Adapt guides/deploying to new sample project's sample-script.js
Apr 16, 2020
162bfd3
[docs] Replace Truffle/Web3 mentions on advanced/bre with Waffle/Ethers
Apr 16, 2020
a84e5a2
[docs] Adapt guides/project-setup to new sample project
Apr 16, 2020
3b5fb73
[docs] Adapt guides/typescript to new sample project
Apr 16, 2020
b322806
[docs] Adapt guides/waffle-testing to use sample project
Apr 16, 2020
67bfad1
[docs] Replace Truffle/Web3 mentions on guides/compile with Waffle/Et…
Apr 17, 2020
58ef974
[docs] Add some Truffle/ethers mentions to docs/buidler-evm
Apr 17, 2020
40b6f86
[docs] Replace Getting Started code with includes
Apr 17, 2020
a00b3ee
[docs] Change guides sidebar order
Apr 17, 2020
d761002
[docs] Adapt guides/truffle-testing due to sample project changes
Apr 17, 2020
c13ca97
Merge remote-tracking branch 'origin/replace-truffle-web3-with-waffle…
Apr 17, 2020
7854c2c
[docs] Some changes after @fzeoli feedback
viarnes Apr 22, 2020
02963e5
[docs] More changes after @fzeoli feedback
viarnes Apr 23, 2020
79c014a
Add solc config option to sample project's config file
viarnes Apr 27, 2020
d19e4e3
[docs] Remove double compile warning from scripts and adjust docs to …
viarnes Apr 28, 2020
3fc9162
[docs] Typo
viarnes Apr 28, 2020
1bb35dc
Merge branch 'development' into replace-truffle-web3-with-waffle-ethers
alcuadrado Apr 28, 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
6 changes: 3 additions & 3 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ module.exports = {
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/truffle-testing.md", "Testing with Web3.js & Truffle", 0],
["/guides/truffle-migration.md", "Migrating from Truffle", 0],
["/guides/deploying.md", "Deploying your contracts", 0],
["/guides/scripts.md", "Writing scripts", 0],
["/guides/buidler-console.md", "Using the Buidler console", 0],
Expand Down Expand Up @@ -225,4 +225,4 @@ module.exports = {
},
}]
]
};
};
44 changes: 22 additions & 22 deletions docs/advanced/buidler-runtime-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The BRE has a role of centralizing coordination across all Buidler components. T

By default, the BRE gives you programmatic access to the task runner and the config system, and exports an [EIP1193-compatible](https://eips.ethereum.org/EIPS/eip-1193) Ethereum provider. You can find more information about [it in its API docs](/api/classes/environment.html).

Plugins can extend the BRE. For example, [buidler-web3](/~https://github.com/nomiclabs/buidler/tree/master/packages/buidler-web3) adds a Web3.js instance to it, making it available to tasks, tests and scripts.
Plugins can extend the BRE. For example, [buidler-ethers](/~https://github.com/nomiclabs/buidler/tree/master/packages/buidler-ethers) adds a Ethers.js instance to it, making it available to tasks, tests and scripts.

### As global variables

Expand All @@ -28,17 +28,36 @@ When writing tests or scripts, you can use `require("@nomiclabs/buidler")` to im

You can import the config DSL explicitly when defining your tasks, and receive the BRE explicitly as an argument to your actions. You can read more about this in [Creating your own tasks](#creating-your-own-tasks).

## Accessing the BRE from outside a task

The BRE can be used from any JavaScript or TypeScript file. To do so, you only have to import it with `require("@nomiclabs/buidler")`. You can do this to keep more control over your development workflow, create your own tools, or to use Buidler with other dev tools from the node.js ecosystem.

Running test directly with [Mocha](https://www.npmjs.com/package/mocha) instead of `npx buidler test` can be done by explicitly importing the BRE in them like this:

```js
const bre = require("@nomiclabs/buidler");
const assert = require("assert");

describe("Buidler Runtime Environment", function() {
it("should have a config field", function() {
assert.notEqual(bre.config, undefined);
});
});
```

This way, tests written for Buidler are just normal Mocha tests. This enables you to run them from your favorite editor without the need of any Buidler-specific plugin. For example, you can [run them from Visual Studio Code using Mocha Test Explorer](../guides/vscode-tests.md).

## Extending the BRE

The BRE only provides the core functionality that users and plugin developers need to start building on top of Buidler. Using it to interface directly with Ethereum in your project can be somewhat harder than expected.

Everything gets easier when you use higher-level libraries, like [Web3.js](https://web3js.readthedocs.io/en/latest/) or [@truffle/contract](https://www.npmjs.com/package/@truffle/contract), but these libraries need some initialization to work, and that could get repetitive.
Everything gets easier when you use higher-level libraries, like [Ethers.js](https://docs.ethers.io/ethers.js/html/) or [ethereum-waffle](https://www.npmjs.com/package/ethereum-waffle), but these libraries need some initialization to work, and that could get repetitive.

Buidler lets you hook into the BRE construction, and extend it with new functionality. This way, you only have to initialize everything once, and your new features or libraries will be available everywhere the BRE is used.

You can do this by adding a BRE extender into a queue. This extender is just a synchronous function that receives the BRE, and adds fields to it with your new functionality. These new fields will also get [injected into the global scope during runtime](#exporting-globally).

For example, adding an instance of Web3.js to the BRE can be done in this way:
For example, adding an instance of [Web3.js](https://web3js.readthedocs.io/en/latest/) to the BRE can be done in this way:

```js
extendEnvironment(bre => {
Expand All @@ -49,22 +68,3 @@ extendEnvironment(bre => {
bre.web3 = new Web3(new Web3HTTPProviderAdapter(bre.network.provider));
});
```

## Accessing the BRE from outside a task

The BRE can be used from any JavaScript or TypeScript file. To do so, you only have to import it with `require("@nomiclabs/buidler")`. You can do this to keep more control over your development workflow, create your own tools, or to use Buidler with other dev tools from the node.js ecosystem.

Running test directly with [Mocha](https://www.npmjs.com/package/mocha) instead of `npx buidler test` can be done by explicitly importing the BRE in them like this:

```js
const bre = require("@nomiclabs/buidler");
const assert = require("assert");

describe("Buidler Runtime Environment", function() {
it("should have a config field", function() {
assert.notEqual(bre.config, undefined);
});
});
```

This way, tests written for Buidler are just normal Mocha tests. This enables you to run them from your favorite editor without the need of any Buidler-specific plugin. For example, you can [run them from Visual Studio Code using Mocha Test Explorer](../guides/vscode-tests.md).
8 changes: 4 additions & 4 deletions docs/buidler-evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Buidler comes built-in with Buidler EVM, a local Ethereum network designed for d

- Buidler will always spin up an instance on startup when `defaultNetwork` is empty or set to `buidlerevm`. It's the default behavior.
- It can be used to run tests, in the console, scripts, and tasks
- Plugins (web3.js, ethers.js, Truffle, etc) connect directly to the provider
- Plugins (ethers.js, web3.js, Waffle, Truffle, etc) connect directly to the provider
- There's no need to make any changes to your tests or scripts.
- It's simply another network and it can be used with `--network`

Expand Down Expand Up @@ -44,7 +44,7 @@ This exception will have a combined JavaScript and Solidity stack
trace: stack traces that start in JavaScript/TypeScript up to your
call to the contract, and continue with the full Solidity call stack.

This is an example of a Buidler EVM exception:
This is an example of a Buidler EVM exception using `TruffleContract`:

```
Error: Transaction reverted: function selector was not recognized and there's no fallback function
Expand Down Expand Up @@ -114,8 +114,8 @@ Buidler EVM allows you to print logging messages and contract variables calling
- `console.logBytes32(bytes32 b)`
- `console.log` implements the same formatting options that can be found in Node.js' [`console.log`](https://nodejs.org/dist/latest-v12.x/docs/api/console.html#console_console_log_data_args), which in turn uses [`util.format`](https://nodejs.org/dist/latest-v12.x/docs/api/util.html#util_util_format_format_args).
- Example: `console.log("Changing owner from %s to %s", currentOwner, newOwner)`
- It works with any library: web3.js, ethers.js, truffle-contract, waffle, etc.
- `console.log` is implemented in standard Solidity and then detected in Buidler EVM. This makes its compilation work with any other tools (like Remix or Truffle).
- It works with any library: ethers.js, web3.js, waffle, truffle-contract, etc.
- `console.log` is implemented in standard Solidity and then detected in Buidler EVM. This makes its compilation work with any other tools (like Remix, Waffle or Truffle).
- `console.log` calls can run in other networks, like mainnet, kovan, ropsten, etc. They do nothing in those networks, but spend a minimal amount of gas.

## Logging
Expand Down
114 changes: 18 additions & 96 deletions docs/getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ $ npx buidler
Quit
```

Let’s create the sample project and go through the steps to try out the sample task and compile, test and deploy the sample contract.
Let’s create the sample project and go through the steps to try out the sample task and compile, test and deploy the sample contract.

The sample project uses the `buidler-truffle5`, which makes Buidler compatible with
tests built for Truffle. You can learn more about it [in this guide](../guides/truffle-testing.md).
For now, all you need to know is that you may need to install some dependencies with

```
npm install --save-dev @nomiclabs/buidler-truffle5 @nomiclabs/buidler-web3 web3
```
The sample project will ask you to install `buidler-waffle` and `buidler-ethers`, which makes Buidler compatible with tests built with Waffle. You can learn more about it [in this guide](../guides/waffle-testing.md).

::: tip
Buidler will let you know how, but in case you missed it you can install them with `npm install --save-dev @nomiclabs/buidler-waffle ethereum-waffle chai @nomiclabs/buidler-ethers ethers`
:::

### Running tasks

Expand Down Expand Up @@ -103,21 +101,7 @@ This is the list of built-in tasks, and the sample `accounts` task. Further ahea

If you take a look at `buidler.config.js`, you will find the definition of the task `accounts`:

```js{5-11}
usePlugin("@nomiclabs/buidler-truffle5");

// This is a sample Buidler task. To learn how to create your own go to
// https://buidler.dev/guides/create-task.html
task("accounts", "Prints the list of accounts", async () => {
const accounts = await web3.eth.getAccounts();

for (const account of accounts) {
console.log(account);
}
});

module.exports = {};
```
<<< @/../packages/buidler-core/sample-project/buidler.config.js{5-11}

To run it, try `npx buidler accounts`:

Expand Down Expand Up @@ -149,32 +133,7 @@ $ npx buidler accounts

Next, if you take a look at `contracts/`, you should be able to find `Greeter.sol:`

```solidity
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;
}

}

```
<<< @/../packages/buidler-core/sample-project/contracts/Greeter.sol

To compile it, simply run:

Expand All @@ -184,24 +143,9 @@ npx buidler compile

### Testing your contracts

The sample project comes with these tests that use [`@truffle/contract`](https://www.npmjs.com/package/@truffle/contract) and
[Web3.js](/~https://github.com/ethereum/web3.js). You can use other libraries if you want, check the integrations described in our guides.

```js
const Greeter = artifacts.require("Greeter");

// Traditional Truffle test
contract("Greeter", accounts => {
it("Should return the new greeting once it's changed", async function() {
const greeter = await Greeter.new("Hello, world!");
assert.equal(await greeter.greet(), "Hello, world!");
The sample project comes with these tests that use [Waffle](https://getwaffle.io/) and [Ethers.js](/~https://github.com/ethers-io/ethers.js/). You can use other libraries if you want, check the integrations described in our guides.

await greeter.setGreeting("Hola, mundo!");

assert.equal(await greeter.greet(), "Hola, mundo!");
});
});
```
<<< @/../packages/buidler-core/sample-project/test/sample-test.js

You can run your tests with `npx buidler test`

Expand All @@ -212,48 +156,26 @@ Compiled 2 contracts successfully


Contract: Greeter
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)
✓ Should return the new greeting once it's changed (762ms)

1 passing (762ms)
```

### Deploying your contracts

Next, to deploy the contract we will use a Buidler script.
Create a file `deploy.js` in `scripts/` with the following code:
Next, to deploy the contract we will use a Buidler script.
Inside `scripts/` you will find `sample-script.js` with the following code:

```js
async function main() {
const Greeter = artifacts.require("Greeter");
<<< @/../packages/buidler-core/sample-project/scripts/sample-script.js

const greeter = await Greeter.new("Hello, Buidler!");
console.log("Greeter deployed to:", greeter.address);
}
Run it with `npx buidler run scripts/sample-script.js`:

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
```
And run it with `npx buidler run scripts/deploy.js`:
```
$ npx buidler run scripts/deploy.js
All contracts have already been compiled, skipping compilation.
Greeter deployed to: 0x080f632fB4211CFc19d1E795F3f3109f221D44C9
Greeter deployed to: 0x7c2C195CD6D34B8F845992d380aADB2730bB9C6F
```

Congrats! You have created a project, ran a Buidler task, compiled a smart contract, installed a Truffle integration plugin, wrote and ran a test using the Truffle plugin, and deployed a contract.
Congrats! You have created a project, ran a Buidler task, compiled a smart contract, installed a Waffle integration plugin, wrote and ran a test using the Waffle and ethers.js plugins, and deployed a contract.

For any questions or feedback you may have, you can find us in the [Buidler Support Telegram group](http://t.me/BuidlerSupport).
7 changes: 2 additions & 5 deletions docs/guides/compile-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To force a compilation you can use the `--force` argument, or run `npx buidler c

## Artifacts

Compiling with Buidler generates one JSON artifact per contract. These are based on Truffle's artifact format, and are compatible with most tools.
Compiling with Buidler generates one JSON artifact per contract. These are compatible with most tools, including Truffle's artifact format.

Each artifact consists of a json with the following properties:

Expand Down Expand Up @@ -72,10 +72,7 @@ module.exports = {

Set your `buidler.config.js` to the following contents:
```js
// assuming you're running Truffle 5 tests.
// There's also buidler-truffle4 if your tests are written for the Truffle 4 API.
// You can use either of them with both versions of Solidity.
usePlugin("@nomiclabs/buidler-truffle5");
usePlugin("@nomiclabs/buidler-waffle");

module.exports = {
paths: {
Expand Down
17 changes: 9 additions & 8 deletions docs/guides/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ with some ideas and we'd value your opinion on how to best design it.

In the meantime, we recommend deploying your smart contracts using
scripts. You can deploy the `Greeter` contract from the sample project
by creating a file `scripts/deploy.js` with these contents
with the deploy script `scripts/sample-script.js`:

```js
// This script uses @nomiclabs/buidler-truffle5
const Greeter = artifacts.require("Greeter");

async function main() {
const greeter = await Greeter.new("Hello, world!");
// We get the contract to deploy
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Buidler!");

await greeter.deployed();

console.log("Greeter address:", greeter.address);
console.log("Greeter deployed to:", greeter.address);
}

main()
Expand All @@ -29,8 +30,8 @@ main()

You can run it with

```sh
npx buidler run --network your-network scripts/deploy.js
```
npx buidler run --network <your-network> scripts/sample-script.js
```

### Truffle migrations support
Expand Down
8 changes: 4 additions & 4 deletions docs/guides/project-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you select _Create a sample project_ a simple project creation wizard will as
```
contracts/
scripts/
tests/
test/
buidler.config.js
```

Expand All @@ -59,17 +59,17 @@ You may have seen this notice when creating the sample project:

```
You need to install these dependencies to run the sample project:
npm install --save-dev web3 @nomiclabs/buidler-web3 @nomiclabs/buidler-truffle5
npm install --save-dev @nomiclabs/buidler-waffle ethereum-waffle chai @nomiclabs/buidler-ethers ethers
```

This stems from the fact that **most of Buidler's functionality comes from plugins**, so check out the [plugins section](../plugins/README.md) for the official list and see if there are any other ones that look interesting.

The sample project uses the `@nomiclabs/buidler-truffle5` plugin, which depends on the `@nomiclabs/buidler-web3` plugin. These integrate the Web3.js and Truffle tools into your project.
The sample project uses the `@nomiclabs/buidler-waffle` plugin, which depends on the `@nomiclabs/buidler-ethers` plugin. These integrate the Ethers.js and Waffle tools into your project.

To use a plugin, the first step is always to install it using `npm` or `yarn`, and then adding a call to `usePlugin(<npm package name>)` in your config file, like this:

```js
usePlugin("@nomiclabs/buidler-truffle5");
usePlugin("@nomiclabs/buidler-waffle");

module.exports = {};
```
Expand Down
Loading