Assignment 3
Assignment 3
Section 2
Assignment # 03
Question # 1
Create a fungible token with ERC20 (extended version ERC223) or a non-fungible token with
ERC 721 (extended version ERC1155) by writing the code and description, along with
screenshots.
Answer:
To create a token, we first installed the MetaMask Browser extension and created our wallet
there. At start, the wallet got 0 ETH as shown in the picture.
To get the token created, we were required to have a minimum ETH amount in our MetaMask
wallet. So, we installed Ganache which provided a Testnet environment having multiple accounts
and a complete network as shown in the image below.
We took the account private key to add the Balance ETH to the MetaMask by clicking on the
Key button in any of the given addresses in the above image.
This private key helped us getting a sample amount of ETH in testnet as shown in the following
image.
Now, the main step is to create the Token with ERC20. We have used remix.ethereum.org to
develop the code file and deploy our own Token to the Ethereum network.
After writing the code, we compiled it successfully and deployed our first token as can be seen in
below image.
Use RSA, generate two prime numbers less than 20 each, generate public and private keys from
the numbers, encrypt and decrypt numbers 1 to 5 using the keys.
Answer:
Question # 3
To incentivize people to come for vote, government has introduced a coin, calling it a VoteCoin,
as cryptocurrency. The government has implemented the incentive system as Blockchain
network
with the following terms:
a. Everyone who votes get 10 VoteCoin, where each VoteCoin is pegged against PKR 100.
b. In case a person is a head of a family and if another of his household votes the voter gets
2 additional VoteCoin for each person to a maximum of 10 coins.
c. In case all the members of his house (the same address in NADRA) votes, the person
gets 5 additional coins.
These coins can only be used to pay electricity bill.
Design logic for smart contract to implement the terms.
Install Solidity, write code to implement the aforementioned logic, and take screenshots.
Answer:
Following is the code snippet.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract VoteCoin {
string public name = "VoteCoin";
string public symbol = "VTC";
uint8 public decimals = 0;
uint256 public totalSupply;
address public government;
modifier onlyGovernment() {
require(msg.sender == government, "Only government can execute this");
_;
}
constructor() {
government = msg.sender;
}
function vote(address voter, address familyHead) external onlyGovernment {
require(!hasVoted[voter], "Already voted");
hasVoted[voter] = true;
if (familyHead != address(0)) {
headOfFamily[voter] = familyHead;
familyVotes[familyHead] += 1;
if (familyVotes[familyHead] <= 5) {
balanceOf[familyHead] += 2;
totalSupply += 2;
emit Transfer(address(0), familyHead, 2);
}
}
}
balanceOf[familyHead] += 5;
totalSupply += 5;
emit Transfer(address(0), familyHead, 5);
}
balanceOf[msg.sender] -= value;
balanceOf[to] += value;
emit Transfer(msg.sender, to, value);
}
}
Question # 4
Create a Private Blockchain Network using Geth & Ganache. Write the smart contract in remix,
and deploy the contract on Metamask connected to the created blockchain. Once the contract is
deployed, do the compilation, migration and testing using the truffle suite.
Answer: We are using Geth & Ganache for creating Private Blockchain Network.