Remix tutorial for moonbeam smart contract developers. Part 1

Lucas | Eaglenode
MATeS of Moonbeam
Published in
4 min readApr 15, 2022

--

Write and deploy your first smart contract on remix

In this tutorial we would like to show you how to write and deploy a smart contract via Remix IDE. It is a well known tool from the Ethereum ecosystem. Given that Moonbeam is EVM compatible, we can run any smart contract written in solidity there.

Before you start you should do the following steps:

!faucet send <address>

First of all you need to search and install the moonbeam extension for Remix IDE. (1) Click icon plugin in the left down corner and (2)search moonbeam extension then (3) click Activate button

Click the moonbeam logo icon (1) and connect with the moonbase alpha network via your metamask. This is testnet for moonbeam chain

After that you should see your account connected with the Moonbase Alpha network.

Write your first smart contract

In this section I will show you how to write a smart contract in solidity. Go to the File explorers sub page (1) and click the Create New File (2). After that, create a file with the name MoonbeamWallet.sol (3).

Copy and paste sample code:

The above contract allows sending ether tokens from any address and only the owner of the contract can withdraw funds.

Deploy your first smart contract

Firstly we need to compile our contract. To do that click the moonbeam icon extension (1) then click the Compile button (2). You should see a green icon after successfully compilation (3). Finally Click the Deploy button (4) and confirm the transaction from metamask (you need to possess a DEV token in your account).

Jump to Moonscan explorer and find your transaction of contract creation. In the picture below you can see the following information:

1. Contract address created after deployment

2. Contract owner. This is your metamask address which you are able to deploy

3. Transaction that contract was released

Explore your first smart contract

I would like to show you how to invoke the contract functions. We can send any amount of DEV to the contract address from any account. Let’s do that from the owner as you can see in the below picture

After that you can make sure that funds are in contract by clicking the getBalance function. As you can see the function returns 1⁰¹⁸ value. It is wei notation. In other words 1 DEV = 1⁰¹⁸ wei

The contract also shows the address and owner. In our case we have:

  • contract address: 0x4865C3D7BF37925Bdc97f7D1E3d9B3e08CF65933
  • owner: 0xEfec18607Dd0F8516C8a14F892B29AF96529bd51

As you can see we have logged events on blockchain. We have used an external payable and withdraw function so we are able to track them on the blockchain explicitly.

Sources:

https://solidity-by-example.org/

--

--