In this series, we have followed fictional character Alice as she builds out a donation system with Ethereum. So far, she has built and tested a smart contract and would now like to deploy it (before starting work on the frontend GUI for her app). After some research on the web, she decides to try out three different approaches with Mist, Truffle and pure JS. To deploy a contract, we need two key pieces of data - the contract ABI (Application Binary Interface) and compiled bytecode.
The Application Binary Interface provides the set of functions and arguments required to interact with a deployed contract as a JSON object. The function definitions in the ABI are hashed when making calls to a deployed contract so it can call methods and retrieve data.
There are many ways to deploy contract code. We can use:
Mist is a popular Ethereum wallet application that runs on Mac, Windows and Linux. It provides a number of tools for interacting with the blockchain including a Dapp browser and Remix IDE - a GUI for writing and deploying contracts. We can simply past contract code into the Remix IDE and click a button to deploy. This tool is also available on the web (you don’t have to download Mist and run a full node to access it).
Using the bytecode and ABI we generated with Remix IDE we can use web3 library to deploy a contract.
If you are browsing via Mist or Chrome with MetaMask plugin enabled, clicking this button will deploy the example contract code (you'll need to wait a minute until it's mined for a response)
Truffle has a slightly more advanced mechanism for deployment. With the previous two methods, we are unable to update our contract if we found a bug. To work around this we can make use of a second contract to route requests to the latest deployed version of our contract code. Note that if a contract contains data (like ours), this would not be migrated and we would need to refactor the code to separate the data we want to keep from the methods that act on that data. Truffle uses the following contract code when issuing command truffle migrate
Relaying without Truffle
We could also use a new feature in the Homestead release of Ethereum called DELEGATECALL. If a method called on a contract does not exist a default unnamed function is called. We can take advantage of this to forward requests and calls to the actual address of our contract, as in this example.