How to migrate existing Aragon App to Buidler plugin
Last updated
Was this helpful?
Last updated
Was this helpful?
For this tutorial, we will assume that you have existing Aragon App which was setup with aragonCLI and now needs migration to the new Builder plugin.
The first step is to install the following NPM development dependencies:
"@aragon/buidler-aragon": "^0.1.0"
"@aragon/contract-test-helpers": "0.0.1"
"@nomiclabs/buidler": "^1.0.2"
"@nomiclabs/buidler-truffle5": "^1.1.2"
"@nomiclabs/buidler-web3": "^1.1.2"
"bignumber.js": "^9.0.0"
"web3": "^1.2.6"
The command for installing the dependencies is:
Most of these dependencies should be new to your project and are related to Nomic Labs' (now Hardhat), a task runner for Ethereum smart contract developers. However, one dependency that you may need to upgrade is web3
, since Aragon's plugin requires v1.2.6
or higher. This may introduce some breaking changes, mostly in tests. See the section for more information.
Since the app won't use aragonCLI
anymore, some NPM scripts need to be changed.
In package.json
:
"postinstall": "yarn compile && yarn build-app"
"build-app": "cd app && npm install && cd .."
"compile": "buidler compile --force"
"start": "buidler start"
"test": "buidler test --network buidlerevm"
Also, make sure that you have the following two scripts in app/package.json
(note that this is a different package.json
than you just edited!):
serve: Launches the webserver (Previously called devserver
script in most projects)
watch: Watches for file changes (Previously called watch:script
script in most projects)
.gitignore
fileAdd the following two folders to your .gitignore
file:
artifacts
cache
Add the following buidler.config.js
file to the root of your project:
appServePort
: The app server port started by the serve
script of the app
folder. (Default: 1234
)
clientServePort
: Aragon client server port.
appSrcPath
: Frontend source for the app.
appBuildOutputPath
: Built app path.
Nevertheless, the following tips can be helpful:
Most truffle contract functions are now asynchronous, so code like this:
should become:
Truffle 5 is using Web3.js 1.2
instead of 0.20
, which comes with a few changes:
Addresses are now mixed-case instead of lower-case.
Numbers returned directly from Web3 are now strings.
Functions that return multiple values now return an object with both named and indexed keys.
You now need to use full Ethereum addresses instead of partial ones like 0x0
. So this address:
would become:
You are now ready to start your app:
You can also uninstall dependencies that are no longer required:
@aragon/cli
ganache-cli
truffle
You can find more information about the Buidler configuration file (now Hardhat). As for the aragon
section, it contains 5 main options:
hooks
: Aragon hooks functions. (See section for more information)
Hooks are custom functions called at various stages of an app initialization. They can be used to execute any logic before or after the app is created and also to specify the app's function parameters. For example, initializing the app with a uint256
and a string
would be as simple as writing the following hook:
If you were using a template contract before to initialize organization state during aragon run
, you should convert the smart contract logic into the hooks. Because hooks are much easier to write, maintain, and debug, the Buidler plugin will not be supporting template contracts. You can find complete examples in 1Hive's and apps. In our case, we will simply add empty functions since we don't need any initialization logic. So we will create a file named buidler-hooks.js
in the scripts
folder and add the following code:
Since the Aragon Buidler plugin uses truffle 5, you may have to migrate part of your tests. You can follow or the .
objects.
Many Web3 utility functions have been moved to
Truffle 5 has also replaced with . Instances of web3.BigNumber()
will therefore have to be changed to web3.utils.toBN()
.
A useful Buidler plugin is available for Solidity code coverage.