Ethereum Tutorials

Deploying Smart Contracts using MetaMask

Deploying contracts with Mist is easy - if you have it connected to a "real" block chain and if it is synchronized. However, it is not ALWAYS easy. For example, recently they broke the "lightning" mode, and using even "fast" mode can take day or two to download... Which is annoying.

In the same time, as you probably have already noticed, there is an alternative (to Geth and Mist that is attached to it) way of accessing blockcjain: let's deploy a contract using MetaMask.

Metamask is a plugin for Chrome browser, it handles passwords internally (safe) and connects fast. You use it to access our "Duke" contract, for example.

First of all, download and install the plugin, the procedure is trivial. As you may not want to keep it always "on", note that you can go to Chrome's "manage plugins" menu, and disable it when you do not need it. Or you can uninstall it, which takes same 10 seconds.

Create an account (again, this is not a MetaMask tutorial, but it is really easy and the program guides you through providing all possible explanations). Add some ether to the account, so that you can pay for deploying of your contract. Also, if you want to practice, select "test" net instead of the real one and "request" money instead of buying it. Once again, this is not a MetaMask tutorial, but... it is still very easy.

As we do not have access to the block chain via Mist in our new case, it means we probably can not use its editor. Of course, by that time you should have a contract that is free of errors, tested using Geth/Mist in private net, but to deploy a contract to the real net, you will need another editor - one that is browser based and Web3.js enabled.

A little clarification: we will use a browser based contracts editor, because MetaMask allows browsers to access the blockchain. So that editor will be able to do deployment... voila!

One of the best browser based Solidity editors if https://ethereum.github.io/browser-solidity. Now, speaking on intuitive interface... it is not.

Replace an example contract with a contract you want to deploy. Compile it (by checking the "Auto Compile", and fix problems, if any.

Enable MetaMask and login in it, then make sure that "Injected Web3" is selected in editor under "Environment". Note that if you opened the page and THEN enabled MetaMask, you will have to reload the page.

Go to the "Run" tab and click "Create": the browser based editor will use Web3.js to run a transaction, which will connect to MataMask, as the result, you will see MetaMask's promt asking to confirm the transaction. If you are not in a hurry, you can reduce gas price to save on transaction cost:

Press submit, and transaction will be sent to network. Make sure you write down or (better) save somewhere the address of a contract you just created.







Visibility is very important for this site. If you like it please link from your page to this URL or share info using Social Buttons below.
(C) snowcron.com, all rights reserved

Please read the disclaimer