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.
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: MITpragmasolidity ^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 valuestringpublic message;// A special function only run during the creation of the contractconstructor(stringmemory 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`functionupdate(stringmemory 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.
Copy/Paste the Smart contract below into the newly created file erc20.sol
Edit the string`` ``public`` ``name & string`` ``public`` ``symbol and replace it with your own name and symbol
Feel free to edit other parts of the contract. This is just a sample ERC20 contract for testing and might not have the necessary security checks in place.
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 name & symbol declares public state variables called name & symbol of type string. The line uint256`` ``public`` ``totalSupply declares a uint256 variable that stores the amount of this particular token in existence. 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.
Events are called Events because they are very good at signalling that an event has taken place. In blockchain terms, they’re cheap. They’re cheap to write in a contract in terms of deployment cost and gas cost when calling a function with an event, and they’re free to read. In short, they’re a very good way of broadcasting relevant information.
For more information on the ERC20 standard and the various variables, you may refer here.
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.
Go to File Explorers, To create a new file , Name it HelloWorld.sol
Go to File Explorers, To create a new file , Name it erc20.sol
Go to Solidity Compiler
After Successful Compilation, it will show
Copy the deployed contract address and input it in Metamask. And step through with adding the custom token.
Hitting will result in a Metamask pop-up. Remember to edit the gas fields to reflect 4000 GasPrice similar to what you did before and voila, you will have minted some of your own tokens.