Skip to content

Deploying Your First Contract

Ethan Wilding edited this page Mar 18, 2016 · 1 revision

Deploying your first dApp

There are several ways to develop and deploy a smart contract, but for this guide we are focusing entirely on using Geth and MeteorJS. If you want a different stack, please consider using the Mix IDE.

In order to deploy your first dApp, we need to get MeteorJS set up. If it isn't already installed on your system, go ahead and install it:

Linux & Mac: From a terminal, run curl https://install.meteor.com/ | sh.

Windows: Download and run the binary installer: https://install.meteor.com/windows

Now that we have MeteorJS installed, we need to grab a dApp from github. Let's try the example from here.

On Linux and Mac you can install and run the example easily from the terminal:

mkdir dapps
cd dapps
git clone https://github.com/SilentCicero/meteor-dapp-boilerplate.git
cd meteor-dapp-boilerplate
cd app
meteor

On Windows you can simply download the zip file from the above link, and extract it into a folder (or use git). Open a command prompt to the app subfolder and type meteor to start it.

Meteor may take a little while to download and install any necessary components, especially if you have Geth mining and taking up all your CPU. After meteor finishes, make sure that you have your Geth rpc instance (described above) back up and running in the background. Some juggling may be required here (i.e. restarting meteor again after you bring geth back up). Once both are running you can now go to http://localhost:3000 to view this app in action. The app is very simple: it just shows the current ether balances of your local wallets. As you mine and refresh the page, you should see the numbers changing.

If the balance functionality is working properly, select the "View2" option from the top right to try deploying a simple "Multiplying" contract. Congratulations! You have deployed an Ethereum smart contract!

Writing and Compiling a Contract of Your Own

To start writing your own on-blockchain "contract" code, you will need a compiler for the Ethereum virtual machine. You could host your own, but using an online version is much easier. For this guide we recommend using Cosmo or Real-time Solidity Compiler, which can both compile your contract and deploy it to the geth client running on your localhost.

To compile your first smart contract, you can select one of the many examples from this tutorial or any of the default examples that Cosmo loads with. You can ignore the instructions on the page about installing your own compiler unless you're interested in doing so.

On the left of Cosmo you will see high level source code for the smart contract. The language these contracts are written in is called "Solidity" but it is very similar to any other object-oriented language such as Java or C++. On the middle right, you can see the contract's interface (which enables it to be easily called) and the opcodes of the compiled contract in the language of the ethereum virtual machine. It is these opcodes which will actually be placed into the blockchain and run.

To connect Cosmo to your running node, change the port in the top right box ("rpc provider") to 8545 and press connect. The console below should say "Web3 Connected."

Now you can press "DEPLOY" above the source code window and the example contract will be automatically deployed to your testing blockchain. You can now use the Methods box to interact with your live contract.

That's it! To begin experimenting, feel free to modify either the MeteorJS boilerplate example, or just play around with smart contract design in Cosmo or Realtime Solidity Compiler. More detailed documentation of the web3 javascript object used to connect your HTML5 apps with Geth and the on-blockchain Solidity smart contracts is available here. We've also made a dApp Builder program that takes your contract code and outputs the HTML, JavaScript, and Bytecode for easy inclusion in your dApp interface.

Clone this wiki locally