In writing smart contracts with Truffle I covered how to get started with Truffle and how to create, test and deploy contracts using an in-memory representation of the blockchain.
The goal of this article is to pick up where we left in that article and deploy it to the testnet Rinkeby. To do so we need to perform the following steps:
- Have a wallet in Rinkeby.
- Configure Truffle to use Rinkeby.
- Deploy code.
geth with Rinkeby and make sure that the correct APIs
for Truffle are enabled.
geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal
If you don’t have
geth or Rinkeby setup, read my article smart
contracts for the
has instructions on how to do so.
Get your account address
Assuming you have an account, open Mist and get the address. For this example I’ll use my main test account
Next, we need to add Rinkeby to our truffle config file. If we open
truffle.js in our contract code we’ll see something like:
Let’s add Rinkeby to the list of networks:
Deploying to Rinkeby
Once we have added Rinkeby to the list of networks, we can deploy our
contract by running the command
truffle migrate --network rinkeby.
Before running the command, we need to unlock our test account so we
can interact with it via Truffle. To do so, stop
geth and start with
the following parameters (replace the account address with yours):
$ geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --unlock="0x0085f8e72391Ce4BB5ce47541C846d059399fA6c"
geth configured, let’s run the migrate command:
We have deploy successfully a contract to Rinkeby using Truffle! We can go to etherscan and see that our contract is there. The following is the information for the contract aboove https://rinkeby.etherscan.io/address/0xbfbbd01ae2ea4bfc777f6ea3a2ad4843c7a104fb.
If we look at the artifacts after the deployment, we’ll see the abi for each of the contracts and the contract address. The following is the artifacts for the HelloWorld contract.
In this article, we picked up on the code from writing smart contracts with Truffle and manage to deploy our contract to the testnet Rinkeby.
In a future article, I’ll cover how to interact with your contracts using Truffle REPL mode. Follow me on twitter (@abuiles) or subscribe to my feed to get updates.
You can find the code and steps for this article in GitHub https://github.com/abuiles/Writing-Smart-Contracts-With-Truffle.