With Remix

Remix IDE is an open source web and desktop application. It fosters a fast development cycle and has a rich set of plugins with intuitive GUIs.

A Hello World style starter project. Deploys a smart contract with a message, and renders it in the front-end. You can change the message using the interactive panel!

This DAPP implements a "Hello World" style application that echoes a message passed to the contract to the front end. This tutorial is intended to be followed using the online IDE available at Remix IDE.

For more information on Remix and how to use it, you may find it in the Remix Documentation.

Setting up Remix IDE

  • Remix IDE - an online IDE to develop smart contracts.

  • If you’re new to Remix, you’ll first need to activate two modules: Solidity Compiler and Deploy and Run Transactions (This should already be activated by default without you needing to search for it in the plugin manager).

  • Search for 'Solidity Compiler' in the plugin tab in Remix (this should be activated by default)

  • And activate the plugins (if they are not already activated)

  • The environment should be set to solidity by default

  • Copy/Paste the Smart contract below into the newly created file HelloWorld.sol

HelloWorld.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Specifies that the source code is for a version
// of Solidity greater than 0.8.10

// A contract is a collliection of functions and data (its state)
// that resides at a specific address on the Ethereum blockchain.
contract HelloWorld {

    // The keyword "public" makes variables accessible from outside a contract
    // and creates a function that other contracts or SDKs can call to access the value
    string public message;

    // A special function only run during the creation of the contract
    constructor(string memory initMessage) {
        // Takes a string value and stores the value in the memory data storage area,
        // setting `message` to that value
        message = initMessage;
    }

    // A publicly accessible function that takes a string as a parameter
    // and updates `message`
    function update(string memory newMessage) public {
        message = newMessage;
    }
}

The first line, pragma solidity ^0.8.0 specifies that the source code is for a Solidity version greater than 0.8.0. Pragmas are common instructions for compilers about how to treat the source code (e.g., pragma once).

A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. The line string public message declares a public state variable called message of type string. You can think of it as a single slot in a database that you can query and alter by calling functions of the code that manages the database. The keyword public automatically generates a function that allows you to access the current value of the state variable from outside of the contract. Without this keyword, other contracts have no way to access the variable.

The constructor is a special function run during the creation of the contract and cannot be called afterward. In this case, it takes a string value initMessage, stores the value in the memory data storage area, and sets message to that value.

The string public message function is another public function that is similar to the constructor, taking a string as a parameter, and updating the message variable.

Compile Smart Contract

  • Select Compiler Version to 0.8.0

  • Now, Compile HelloWorld.sol /ERC20.sol

  • Now, we have to deploy our smart contract on f(x)Core Network. For that, we have to connect to web3, this can be done by using services like Metamask. We will be using Metamask. Please follow this tutorial to setup a Metamask Account.

  • Open Metamask, click the network dropdown and then click 'Add Network'. For more information on MetaMask and how to configure it to your network, you may check out this Metamask guide.

  • Put in a Network name (just an example):

fxtothemoon
  • In New RPC URL field you can add the URL:

https://testnet-fx-json-web3.functionx.io:8545
  • Enter the Chain ID:

90001
  • (Optional Field) Currency Symbol (just an example):

FX
  • (Optional Field) Block Explorer URL:

https://testnet-explorer.functionx.io/evm
  • Click Save

  • Copy your address from Metamask

  • Head over to faucet and request test FX - you will need this to pay for gas on f(x)Core. After inputting your wallet address in, select the option '100 (fxCore) FX / 24h'.

  • Now, let's Deploy the Smart Contract to the f(x)Core Network

  • Select Injected Web3 in the Environment dropdown ensure you have selected the right contract too.

  • Accept the connection request by clicking Next in Metamask after choosing the account

  • Once Metamask is connected to Remix, the ‘Deploy’ transaction would generate another metamask popup that requires transaction confirmation.

  • Click the EDIT button (1st picture) and then the Edit suggested gas fee (2nd picture) before editing the Max priority fee and Max fee to 4000 Gwei then click SAVE.

  • Click Confirm

Congratulations! You have successfully deployed HelloWorld/ERC20 Smart Contract. Now you can interact with the Smart Contract. Check the deployment status here.

ERC20 Tutorial Extended

After deploying the ERC20.sol, your Remix should look something like the following:

Taking a look at the side panel in particular these sets of button functions where you can interact with the contract. By clicking on the drop down for those buttons that have a dropdown will require that you fill in those fields before clicking on the button to query/write the value of the function. For those buttons that do not have a field to fill in, you may just click on the button to read/write.

Orange buttons are writeable button functions. Blue buttons are readable button functions

Now with our custom token added, we are all ready to mint some tokens and interact with the ERC20 contract.

Clicking into the _mint (example) dropdown, you will be shown a few fields:

The fields are pretty self explanatory. Amount has to be of the type unit256 (unsigned integer), while Account has to be of the address (0x) type. Input your address and the amount you would like to mint. Do remember to add 18 0s behind. The amount value here is expressed in Wei. So if you want to mint 100 of your tokens, the field should be 100000000000000000000.

Now lets go through the rest of the buttons one by one:

totalSupply() → uint256

Returns the amount of tokens in existence.

symbol() → string

Returns the symbol of the token, usually a shorter version of the name.

name() → string

Returns the name of the token.

decimals() → uint8

Returns the number of decimals used to get its user representation. For example, if decimals equals 2, a balance of 505 tokens should be displayed to a user as 5,05 (505 / 10 ** 2).

Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei.

balanceOf(address account) → uint256

Returns the amount of tokens owned by account.

Do not forget to fill in the account field with the 0x address you would like to query.

allowance(address owner, address spender) → uint256

Returns the remaining number of tokens that spender will be allowed to spend on behalf of owner through transferFrom. This is zero by default.

This value changes when approve or transferFrom are called.

transferFrom(address sender, address recipient, uint256 amount) → bool

Moves amount tokens from sender to recipient using the allowance mechanism. amount is then deducted from the caller’s allowance.

Returns a boolean value indicating whether the operation succeeded.

Emits a Transfer event.

transfer(address recipient, uint256 amount) → bool

Moves amount tokens from the caller’s account to recipient.

Returns a boolean value indicating whether the operation succeeded.

Emits a Transfer event.

approve(address spender, uint256 amount) → bool

Sets amount as the allowance of spender over the caller’s tokens.

Returns a boolean value indicating whether the operation succeeded.

Emits an Approval event.

_mint(address account, uint256 amount)

Creates amount tokens and assigns them to account, increasing the total supply.

Emits a transfer event with from set to the zero address.

Requirements

  • to cannot be the zero address.

Last updated