Skip to content

Instantly share code, notes, and snippets.

View Zeegaths's full-sized avatar
🎯
Focusing

Mary Wangui Zeegaths

🎯
Focusing
View GitHub Profile
@Zeegaths
Zeegaths / Explanation
Created January 27, 2024 19:05
Staking Contract
The contract allows users to stakes tokens using the staking Token and get ther rewards using the rewards token. There are a number of features included in the cntract to ensure that it runs smoothly. These include:
-Pragma declaration: Defines the solidity version to be used for the contract (version 0.5.16 and higher).
-The imports are used to bring in various functionalities from OpenZappelinlibrary such as safemath mathematical operations, ERC20 transferes and security against reentrancy.
-It also inherits multiple contracts and interfaces to acces their functionality.
-The contract declares various state variables for staking and rewards, defining the timing for reward distribution, store data about the participants and track the individual balances and the total staked tokens.
-THe constructor uses the reward token, distribution, staking addresses and the owner to initialize the contract.
@Zeegaths
Zeegaths / function.sol
Last active January 28, 2024 22:40
A smart contract that uses view, pure, and payable functions.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract Function {
uint public a = 5;
// View function
function multiplyNumbers(uint b) public view returns (uint) {
return a * b;
}
@Zeegaths
Zeegaths / app.js
Last active February 3, 2024 13:26
A smart contract that triggers and emits 3 events
let contract_abi = [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
@Zeegaths
Zeegaths / global.sol
Created January 29, 2024 00:52
A smart contract that uses global functions in the message context
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
// Write a smart contract that defines and triggers 3-4 events
// Index the events so that they can be easily searched
// Capture these events in your JavaScript code
contract Events {
uint public x = 0;
event AddressLog(address indexed sender, string message);
@Zeegaths
Zeegaths / School.sol
Last active February 8, 2024 22:47
School database
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract School {
enum Rank {
Principle,
Teacher,
Student
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./School.sol";
contract SchoolFactory {
School public schoolSystem;
@Zeegaths
Zeegaths / Storage.sol
Created February 11, 2024 12:01
A smart contract that has both storage and memory types of variables in it
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract Storage {
struct student{
string Name;
uint Age;
}
import {
time,
loadFixture,
} from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
import { expect } from "chai";
import { ethers } from "hardhat";
describe("Todo List", function () {
async function deployTodoList() {
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract ZarahToken is ERC721URIStorage, Ownable {
constructor() ERC721("ZarahToken", "ZT") Ownable (msg.sender) {}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract DepositFunds {
//track the balance
mapping(address => uint) deposits;
//deposit function
function deposit(uint _amount) external payable {