Smart Contracts With Remix IDE
Contents
Preparations
- Installed the MetaMask and created a account.
- Added the Goerli testnet in MetaMask.
- Obtained the Goerli’s ETH.
- Free https://goerlifaucet.com/ (Need to complete the registration first)
Remix IDE
Quickly Create a Smart Contracts Via Remix IDE
❖ First connect to remix.ethereum.org website. ❖ Create an empty workspace.
❖ Create a New File "HelloWorld.sol"(.prettierrc.json can delete it).
❖ Enter the following code in "HelloWorld.sol" file.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract HelloWorldToken is ERC20, Ownable {
constructor() ERC20("HelloWorldToken", "HWTK") {
_mint(msg.sender, 1000 * 10 ** decimals());
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
❖ Compile "HelloWorld.sol". ❖ After the compilation is complete, you will get a ✅.
Deploy & Run Transaction
❖ Login MetaMask and select Goerli test network.
❖ Select Deploy & Run Transaction in Remix IDE. ❖ Select Injected Provider - MetaMask in ENVPONMENT.
❖ Deploy and Confirm (will pop up a MetaMask Notification window).
❖ When you finish Deploy, you will see the contract information in the Deployed Contracts field. ❖ When you want to import tokens, you need to copy the token contract address of HelloWorld first.
❖ Paste the copied HelloWorld's contract address into the Token contract address field and select "Add custom token" and "Import tokens".
❖ Completing HWTK's Smart Contracts.