Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonu zkthon #388

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions solution-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts@4.8.2/token/ERC20/ERC20.sol";

import "@openzeppelin/contracts@4.8.2/token/ERC20/extensions/ERC20Burnable.sol";

import "@openzeppelin/contracts@4.8.2/access/Ownable.sol";

contract Sonu is ERC20, ERC20Burnable, Ownable {

constructor() ERC20("Sonu", "SON") {
_mint(msg.sender, 100000 * 10 ** decimals());
}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
118 changes: 118 additions & 0 deletions solution-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

URL - https://testnet-zkevm.polygonscan.com/tx/0x24b662faba9d155d3d183ada601a5e1eeceb331704f5236911d6c2386963df67

Contract Address - 0x30a7755f65bbbe16ae33c3175023a0fe1172262a

0x24b662faba9d155d3d183ada601a5e1eeceb331704f5236911d6c2386963df67




## Code

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1></h1>
<p><span id="currentSubmission"></span></p>
<label for="newUsername"></label>
<input type="text" id="newUsername" />
<button class="submit-btn"></button>

<script>
// Check if MetaMask is installed and connected
if (window.ethereum) {
const web3 = new Web3(window.ethereum);

// Request account access if needed
window.ethereum
.request({ method: "eth_requestAccounts" })
.then(() => {
// Define contract ABI
const abi = [
{
inputs: [
{
internalType: "string",
name: "_username",
type: "string",
},
],
stateMutability: "nonpayable",
type: "constructor",
},
{
inputs: [],
name: "getCurrentSubmission",
outputs: [
{
internalType: "string",
name: "",
type: "string",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "string",
name: "_username",
type: "string",
},
],
name: "submitUsername",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];

// Define contract address
const contractAddress =
"0x30a7755f65bbbe16ae33c3175023a0fe1172262a";

// Create contract instance
const contract = new web3.eth.Contract(abi, contractAddress);
console.log(contract);

// Display current submission on page load
contract.methods.getCurrentSubmission().call((error, result) => {
if (error) {
console.error(error);
return;
}
document.getElementById("currentSubmission").textContent = result;
});

// Submit new username on button click
const btn = document.querySelector(".submit-btn");
function submitUsername() {
const newUsername = document.getElementById("newUsername").value;
contract.methods
.submitUsername(newUsername)
.send(
{ from: web3.eth.defaultAccount },
(error, transactionHash) => {
if (error) {
console.error(error);
return;
}
console.log("Transaction hash:", transactionHash);
}
);
}
btn.addEventListener("click", submitUsername);
})
.catch((error) => {
console.error(error);
});
} else {
console.error("MetaMask not detected");
}
</script>
</body>
</html>