Deploying contracts with truffle
Using truffle makes deploying contracts simply a matter of configuration, though the configuration is not always obvious. See below for information on truffle configuration.
Truffle v4 gives poor, or sometimes no error messages. Example.
Truffle v5* does a lot better with providing logging information and error messages. (The beta was just released at the time of writing.)
To install and use truffle v5 (as a developer dependency)
Truffle configuration
Truffle looks for configuration settings in truffle.js
(apparently truffle-config.js
on Windows?).
To deploy to a local development network, for testing purposes, ensure that either ganache or ganache-cli is running, and that the "development" network is configured. If truffle migrate
is not passed a specific network, then development
is used by default.
To deploy to a public network, you need to either provide a connection to a local ethereum node (eg. running with geth
or parity
) or a "custom provider".
Syncing an ethereum node consumes a lot of disk space, and is impractical for development TODO: explore light ethereum clients.
Configuring a custom provider is a good, lightweight solution. Infura seems to work well, and is easy to configure:
The mnenomic, stored in ${TRUFFLE_ROOT_FOLDER}/.env
, generates keys according to BIP39. I used Ian Coleman's generator. Be sure to set the coin to Ethereum. By default, truffle sends transactions from the first account generated by this mnemonic, so ensure that this account has a balance on whichever network you're using (see below). This can be overruled by passing the index of the address you want to use to the provider HDWalletProvider
constructor.
Test networks
Infura offers endpoints for MAINNET, the network which actually holds value, as well as three testnets: Ropsten, Rinkeby and Kovan.
Kovan seems to be the most user-friendly of the 3, with it being very simple to request "kether" (kovan-ether) via a faucet, and having fast transactions.
In comparison, this transaction on the Ropsten has been pending for over 2 hours, as of the time of writing. (This shouldn't be normal.)
See here for a brief comparison of the test networks.
Last updated