In this tutorial I’m going to show you the easiest way to deploy a smart contract on Ethereum.

If you want to deploy your own contract, you’ll need to download MetaMask. That’s the only requirement for this tutorial!

Install MetaMask

MetaMask is a browser extension that manages your Ethereum wallet and connects your browser to the blockchain. This connection enables you to send transactions to the Ethereum network. MetaMask is currently available for Chrome, Brave, Firefox, and Opera.

After you install MetaMask, follow the setup instructions to create a wallet. Make sure to safely store your mnemonic phrase and pick a secure password.

Craft a Contract

Let’s jump right into making a contract. It’s easy to do this on Pragma, a web platform for Ethereum development. Head over to Pragma and make an account. Once you do, you can click into the Editor, shown below.

Solidity editor in Pragma

As you can see here, Pragma starts you off with a simple token contract. This isn’t an official Ethereum token, but rather a more basic implementation. It’s fine for this example though, so change the name of your coin to whatever you want, as seen on lines 4 and 17 in the picture above.

Get some Testnet Ether

It’s time to deploy our contract, but we don’t want to spend any real ETH for this example. Luckily there’s an easy way to do this for free.

When people refer to the Ethereum network, they’re usually talking about the “mainnet”. However, there are also some test networks that you can use to test or debug your code.

We’ll use one of these test networks, called Rinkeby, where we can get some free test ETH.

Start by switching MetaMask over to the Rinkeby network, as shown in the picture below.

Network selector in MetaMask

Now, you need to use a website called a “faucet” that will send some Rinkeby test ETH into our account. Follow the instructions on the Rinkeby faucet website to get some.

Unfortunately, this process isn’t instant. It might take awhile for the ETH to show up in your wallet, since there is a waiting period while the transaction is confirmed. Hopefully this will change in the future.

Once you’ve got the ETH in your MetaMask account, you’re ready to go.

Deploy the Contract

We’re not going to go over Solidity in this tutorial, but let’s go through what this smart contract does.

The contract has these main parts

minter: This variable will be set to your Ethereum account address when the contract is deployed. balances: A mapping to keep track of how many coins each address holds. mint: A function that creates new coins. Only your account can call this function send: A function for sending coins from one account to another

There are also two events, which we’ll see later on.

To deploy your contract, click the deploy button in the top right of the editor. This will compile your contract and bring up a modal asking you to choose which contract to deploy. Since we only have one contract in the editor, your contract should already be selected in the input. Next, MetaMask will bring up a new window asking you to confirm your transaction. This is the step that actually deploys your contract code to the Rinkeby blockchain. Click the green submit button, and the progress modal in Pragma will move into the pending state. Your contract code has been submitted to the blockchain, and the transaction is waiting to be mined. Once your transaction is mined, you will see this screen.

Successful deployment modal

Now you’re ready to start using your contract. Click the Contracts button.

View your Contracts

The contracts page lists all the contracts you’ve deployed before. You should see your contract in the table. From the actions dropdown on the right side, you can go to the logs for your contract, interact with your contract, edit your contracts details, or delete your contract from the list. It is important to note that deleting your contract from the list does not delete it from the blockchain. Once your contract is deployed to the Ethereum network, it is there permanently (unless you implement selfdestruct).

From the actions dropdown, click on the Interact option.

Interact with your Contract

A generated UI for your smart contract

The Interact page generates a UI that connects to your contract. The page is split into two sections: Getters and Setters. Getters allow you to read information from your contract. Setters allow you to write new information to your contract on the blockchain, which will trigger a transaction in MetaMask.

Here are some things to do with the contract

In the Getters section, find the “minter” function and click Submit. The output should be your own Ethereum address from MetaMask. Copy your address and paste it into the input for “balances”, and then click submit. You should see the value “0”. To give yourself some coins, you need to call “mint” in the Setters section. Paste your address into the “receiver” input, type 100 in the “amount” input, and click Submit. After confirming in a new MetaMask popup, your transaction is being mined. This step can take some time, but once it’s finished, you can check your balance again and see the value 100. To send some coins to other users, you can repeat the steps above in the “send” function.

Share your Contract

There’s a toggle on the Interact page for making your contract shareable. If you turn this on, you’ll get a link you can share wherever you want, which will allow other people to interact with your contract as well. This can be useful for testing your code, or just using a simple smart contract with your friends.

View your Logs

Realtime logs view for your smart contract

Every time the “mint” and “send” methods are called, an event from your contract will be logged. You can view all of the events from your contract in the logging view in Pragma. Click “Logging” in the subnav menu, and you should see one event for your minted coins. This logging view will load events as they happen in real-time.

Conclusion

That’s it! Thanks for reading, and if you want to start a conversation about Ethereum, Solidity, or dapp development, feel free to reach out to me on twitter.