Basic ERC-20 smart-contract on Parastate’s testnet

Blax Market
4 min readApr 26, 2021

Hello to all future Parastate’s developers! This is manual of creating simple ERC-20 smart contract. We will use same Solidity code used for Ethereum contracts. This makes coding as well as transfer contracts and dapps from Ethereum network for Parastate really easy!

First of all, we need to set your Metamask access for Parastate’s network. Your custom RPC:

Network Name: ParaState

New RPC URL: https://rpc.parastate.io:8545

Chain ID: 123

Currency Symbol (Optional): STATE

Next step is to add test STATE token to your wallet using this faucet faucet http://faucet.parastate.io

After wehave 1 test STATE we can start using BUIDL for Parastate https://buidl.secondstate.io/

Here we can clean the code and choose Solidity version. For our project we are going to use Solidity 0.6.12.

The next and cool step is that we can choose BUIDL for a dark theme!

We need to set our Metamask account in “Accounts”. Import your Private Key.

After that add Parastate network in “Providers”. Web3 RPC endpoint is

https://rpc.parastate.io:8545/

For our smart contract we will use SafeMath simple library.

Let’s add Ownable contract.

And our main contract with STT token.

Let’s deploy it to the chain.

Now we can mint some tokens. I’ve made it with 2 decimals for usability.

Let’s add one more test account to Metamask which we will use to receive test tokens.

Let’s check our balance.

To send some tokens we should approve it for our new generated address.

This is what we are going to see in allowance.

And finally send it to our new account.

Now we can add it to our Metamask using address in “Deployed”.

Full code:

pragma solidity ^0.6.12;

library SafeMath {
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a — b;
}

function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}

contract Ownable {
address private _owner;

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
modifier onlyOwner() {
require (isOwner(), “Ownable: caller is not the owner”);
_;
}
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function _transferOwnership(address newOwner) internal {
require (newOwner != address(0), “Ownable: new owner is zero adress”);
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}

contract myToken is Ownable{
using SafeMath for uint;
string public constant name = “SolidityTestToken”;
string public constant symbol = “STT”;
uint8 public constant decimals = 2;

uint public totalSupply;

mapping (address => uint) balances;

mapping (address => mapping(address => uint)) allowed;

event Transfer(address indexed _from, address indexed _to, uint _value );
event Approval(address indexed _from, address indexed _to, uint _value );

function mint(address to, uint value) onlyOwner public {
balances[to] = balances[to].add(value);
totalSupply = totalSupply.add(value);
}
function balanceOf(address owner) public view returns(uint) {
return balances[owner];
}
function allowance(address _owner, address _spender) public view returns(uint) {
return allowed[_owner][_spender];
}

function transfer(address _to, uint _value) public {
require (balances[msg.sender] >= _value) ;
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
}
function transferFrom(address _from, address _to, uint _value) public {
require (balances[_from] >= _value && allowed[_from][msg.sender] >= _value);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
}
function approve(address _spender, uint _value) public {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
}
}

I hope this manual was useful for you. All other neccessary information you can find in offical Parastate Medium page https://medium.com/ethereum-on-steroids. Looking forward for your great smart contracts and dApps!

--

--