├── README.md ├── base.sol ├── berachain.sol ├── ethereum.sol ├── linea.sol └── monad.sol /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # 📝 Smart Contracts Repository for Popular Blockchain Networks 4 | 5 | Welcome to the **Smart Contracts Repository**! This repository contains a collection of smart contracts developed for some of the most widely-used blockchain networks. Each contract is tailored to the specifications of its respective network, providing developers with a wide range of examples to work with. Whether you're working on Ethereum, Binance Smart Chain, Solana, or other platforms, you'll find useful contract examples here. 6 | 7 | ## 🌐 Supported Networks 8 | 9 | This repository includes smart contracts for the following blockchain networks 10 | 11 | - **Ethereum** 12 | - **Linea** 13 | - **Base** 14 | - **Berachain** 15 | - **Monad** 16 | 17 | ## 🛠️ Prerequisites 18 | 19 | To work with the smart contracts in this repository, you'll need the following development tools: 20 | 21 | - **Node.js** (v14 or higher) 22 | - **Truffle** or **Hardhat** (for Ethereum, BSC, Polygon, etc.) 23 | - **Solana CLI** (for Solana-specific smart contracts) 24 | - **MetaMask** or other compatible wallets for testing 25 | - **Remix IDE** (optional) for quick contract testing and deployment 26 | 27 | ### Installation 28 | 29 | 1. Clone the repository: 30 | 31 | ```bash 32 | git clone https://github.com/mdqst/contracts.git 33 | cd contracts 34 | ``` 35 | 36 | 2. Install the dependencies: 37 | 38 | - For EVM contracts: 39 | 40 | ```bash 41 | npm install 42 | ``` 43 | 44 | - For Solana contracts: 45 | 46 | Make sure you have **Rust** and **Solana CLI** installed. Follow the [Solana installation guide](https://docs.solana.com/cli/install-solana-cli-tools) if needed. 47 | 48 | ## 🚀 Deployment 49 | 50 | Each folder contains deployment guides for deploying the smart contracts on their respective networks. 51 | 52 | ### For EVM-Compatible Networks (Ethereum, BSC, Polygon, etc.): 53 | 54 | You can use **Hardhat** or **Truffle** to deploy smart contracts: 55 | 56 | 1. **Deploy with Truffle**: 57 | 58 | ```bash 59 | truffle migrate --network 60 | ``` 61 | 62 | 2. **Deploy with Hardhat**: 63 | 64 | ```bash 65 | npx hardhat run scripts/deploy.js --network 66 | ``` 67 | 68 | ### For Solana: 69 | 70 | 1. **Build the contract**: 71 | 72 | ```bash 73 | cargo build-bpf 74 | ``` 75 | 76 | 2. **Deploy the contract**: 77 | 78 | ```bash 79 | solana program deploy 80 | ``` 81 | 82 | ## 🔗 Testing 83 | 84 | Each contract comes with a set of tests written using **Mocha/Chai** (for EVM) or **Rust tests** (for Solana). You can run the tests for EVM-compatible networks using: 85 | 86 | ```bash 87 | npx hardhat test 88 | ``` 89 | 90 | For Solana, run: 91 | 92 | ```bash 93 | cargo test 94 | ``` 95 | 96 | ## 📝 License 97 | 98 | This repository is licensed under the **MIT License**. Feel free to use, modify, and distribute the smart contracts within this repository for personal or commercial use. 99 | 100 | ## 🤝 Contributing 101 | 102 | Contributions are welcome! If you'd like to add a contract for a new blockchain network or improve existing contracts, feel free to submit a pull request. 103 | 104 | 1. Fork the repository 105 | 2. Create a new branch (`git checkout -b feature/your-feature`) 106 | 3. Commit your changes (`git commit -m 'Add new feature'`) 107 | 4. Push to the branch (`git push origin feature/your-feature`) 108 | 5. Open a pull request 109 | 110 | ## 📧 Contact 111 | 112 | If you have any questions, feel free to reach out via email or create an issue in this repository. 113 | 114 | --- 115 | 116 | Enjoy working with smart contracts and happy coding! 🎉 117 | 118 | -------------------------------------------------------------------------------- /base.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | // ERC20 standard interface 5 | interface IERC20 { 6 | function totalSupply() external view returns (uint256); 7 | function balanceOf(address account) external view returns (uint256); 8 | function transfer(address recipient, uint256 amount) external returns (bool); 9 | function allowance(address owner, address spender) external view returns (uint256); 10 | function approve(address spender, uint256 amount) external returns (bool); 11 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 12 | 13 | event Transfer(address indexed from, address indexed to, uint256 value); 14 | event Approval(address indexed owner, address indexed spender, uint256 value); 15 | } 16 | 17 | contract MyToken is IERC20 { 18 | string public name = "MyToken"; // Token name 19 | string public symbol = "MTK"; // Token symbol 20 | uint8 public decimals = 18; // Decimal places 21 | uint256 private _totalSupply; 22 | 23 | mapping(address => uint256) private _balances; 24 | mapping(address => mapping(address => uint256)) private _allowances; 25 | 26 | constructor(uint256 initialSupply) { 27 | _totalSupply = initialSupply * (10 ** uint256(decimals)); // Set the total supply with decimals 28 | _balances[msg.sender] = _totalSupply; // Assign all tokens to the contract creator 29 | emit Transfer(address(0), msg.sender, _totalSupply); // Emit transfer event from the zero address 30 | } 31 | 32 | // Total supply of the token 33 | function totalSupply() public view override returns (uint256) { 34 | return _totalSupply; 35 | } 36 | 37 | // Balance of a specific account 38 | function balanceOf(address account) public view override returns (uint256) { 39 | return _balances[account]; 40 | } 41 | 42 | // Transfer tokens to a specified address 43 | function transfer(address recipient, uint256 amount) public override returns (bool) { 44 | require(_balances[msg.sender] >= amount, "Insufficient balance"); 45 | _balances[msg.sender] -= amount; 46 | _balances[recipient] += amount; 47 | emit Transfer(msg.sender, recipient, amount); 48 | return true; 49 | } 50 | 51 | // Allowance given by the token owner to a spender 52 | function allowance(address owner, address spender) public view override returns (uint256) { 53 | return _allowances[owner][spender]; 54 | } 55 | 56 | // Approve an address to spend tokens on behalf of the owner 57 | function approve(address spender, uint256 amount) public override returns (bool) { 58 | _allowances[msg.sender][spender] = amount; 59 | emit Approval(msg.sender, spender, amount); 60 | return true; 61 | } 62 | 63 | // Transfer tokens from one address to another using allowance 64 | function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { 65 | require(_balances[sender] >= amount, "Insufficient balance"); 66 | require(_allowances[sender][msg.sender] >= amount, "Allowance exceeded"); 67 | 68 | _balances[sender] -= amount; 69 | _balances[recipient] += amount; 70 | _allowances[sender][msg.sender] -= amount; 71 | 72 | emit Transfer(sender, recipient, amount); 73 | return true; 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /berachain.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | // ERC20 standard interface 5 | interface IERC20 { 6 | function totalSupply() external view returns (uint256); 7 | function balanceOf(address account) external view returns (uint256); 8 | function transfer(address recipient, uint256 amount) external returns (bool); 9 | function allowance(address owner, address spender) external view returns (uint256); 10 | function approve(address spender, uint256 amount) external returns (bool); 11 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 12 | 13 | event Transfer(address indexed from, address indexed to, uint256 value); 14 | event Approval(address indexed owner, address indexed spender, uint256 value); 15 | } 16 | 17 | contract BerachainToken is IERC20 { 18 | string public name = "BerachainToken"; 19 | string public symbol = "BRC"; 20 | uint8 public decimals = 18; 21 | uint256 private _totalSupply; 22 | 23 | mapping(address => uint256) private _balances; 24 | mapping(address => mapping(address => uint256)) private _allowances; 25 | 26 | address public owner; 27 | 28 | modifier onlyOwner() { 29 | require(msg.sender == owner, "Only the contract owner can perform this action"); 30 | _; 31 | } 32 | 33 | constructor(uint256 initialSupply) { 34 | owner = msg.sender; // Contract deployer becomes the owner 35 | _totalSupply = initialSupply * (10 ** uint256(decimals)); // Initial supply with decimals 36 | _balances[owner] = _totalSupply; // Assign the total supply to the owner 37 | emit Transfer(address(0), owner, _totalSupply); // Emit the initial transfer event 38 | } 39 | 40 | // Return the total supply of tokens 41 | function totalSupply() public view override returns (uint256) { 42 | return _totalSupply; 43 | } 44 | 45 | // Return the balance of a specific account 46 | function balanceOf(address account) public view override returns (uint256) { 47 | return _balances[account]; 48 | } 49 | 50 | // Transfer tokens to a recipient 51 | function transfer(address recipient, uint256 amount) public override returns (bool) { 52 | require(_balances[msg.sender] >= amount, "Insufficient balance"); 53 | _balances[msg.sender] -= amount; 54 | _balances[recipient] += amount; 55 | emit Transfer(msg.sender, recipient, amount); 56 | return true; 57 | } 58 | 59 | // Check how much a spender is allowed to spend on behalf of an owner 60 | function allowance(address owner, address spender) public view override returns (uint256) { 61 | return _allowances[owner][spender]; 62 | } 63 | 64 | // Approve a spender to spend tokens on behalf of the owner 65 | function approve(address spender, uint256 amount) public override returns (bool) { 66 | _allowances[msg.sender][spender] = amount; 67 | emit Approval(msg.sender, spender, amount); 68 | return true; 69 | } 70 | 71 | // Transfer tokens on behalf of the owner using an approved allowance 72 | function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { 73 | require(_balances[sender] >= amount, "Insufficient balance"); 74 | require(_allowances[sender][msg.sender] >= amount, "Allowance exceeded"); 75 | 76 | _balances[sender] -= amount; 77 | _balances[recipient] += amount; 78 | _allowances[sender][msg.sender] -= amount; 79 | 80 | emit Transfer(sender, recipient, amount); 81 | return true; 82 | } 83 | 84 | // Mint new tokens (only the owner can mint new tokens) 85 | function mint(uint256 amount) public onlyOwner { 86 | _totalSupply += amount * (10 ** uint256(decimals)); 87 | _balances[owner] += amount * (10 ** uint256(decimals)); 88 | emit Transfer(address(0), owner, amount * (10 ** uint256(decimals))); 89 | } 90 | 91 | // Burn tokens (destroy tokens from the owner's balance) 92 | function burn(uint256 amount) public onlyOwner { 93 | require(_balances[owner] >= amount, "Insufficient tokens to burn"); 94 | _totalSupply -= amount * (10 ** uint256(decimals)); 95 | _balances[owner] -= amount * (10 ** uint256(decimals)); 96 | emit Transfer(owner, address(0), amount * (10 ** uint256(decimals))); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /ethereum.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | // ERC20 standard interface 5 | interface IERC20 { 6 | function totalSupply() external view returns (uint256); 7 | function balanceOf(address account) external view returns (uint256); 8 | function transfer(address recipient, uint256 amount) external returns (bool); 9 | function allowance(address owner, address spender) external view returns (uint256); 10 | function approve(address spender, uint256 amount) external returns (bool); 11 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 12 | 13 | event Transfer(address indexed from, address indexed to, uint256 value); 14 | event Approval(address indexed owner, address indexed spender, uint256 value); 15 | } 16 | 17 | contract MyToken is IERC20 { 18 | string public name = "MyToken"; 19 | string public symbol = "MTK"; 20 | uint8 public decimals = 18; 21 | uint256 private _totalSupply; 22 | 23 | mapping(address => uint256) private _balances; 24 | mapping(address => mapping(address => uint256)) private _allowances; 25 | 26 | address public owner; 27 | 28 | modifier onlyOwner() { 29 | require(msg.sender == owner, "Only the owner can perform this action"); 30 | _; 31 | } 32 | 33 | constructor(uint256 initialSupply) { 34 | owner = msg.sender; // The contract deployer becomes the owner 35 | _totalSupply = initialSupply * (10 ** uint256(decimals)); // Set the total supply with the decimal factor 36 | _balances[owner] = _totalSupply; // Assign the entire supply to the owner 37 | emit Transfer(address(0), owner, _totalSupply); // Emit a transfer event from 0x0 to owner 38 | } 39 | 40 | // Return the total supply of the token 41 | function totalSupply() public view override returns (uint256) { 42 | return _totalSupply; 43 | } 44 | 45 | // Return the balance of a specific account 46 | function balanceOf(address account) public view override returns (uint256) { 47 | return _balances[account]; 48 | } 49 | 50 | // Transfer tokens to a recipient 51 | function transfer(address recipient, uint256 amount) public override returns (bool) { 52 | require(_balances[msg.sender] >= amount, "Insufficient balance"); 53 | _balances[msg.sender] -= amount; 54 | _balances[recipient] += amount; 55 | emit Transfer(msg.sender, recipient, amount); 56 | return true; 57 | } 58 | 59 | // Allow spender to spend a specified amount of tokens on behalf of the owner 60 | function approve(address spender, uint256 amount) public override returns (bool) { 61 | _allowances[msg.sender][spender] = amount; 62 | emit Approval(msg.sender, spender, amount); 63 | return true; 64 | } 65 | 66 | // Transfer tokens on behalf of an owner using an approved allowance 67 | function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { 68 | require(_balances[sender] >= amount, "Insufficient balance"); 69 | require(_allowances[sender][msg.sender] >= amount, "Allowance exceeded"); 70 | 71 | _balances[sender] -= amount; 72 | _balances[recipient] += amount; 73 | _allowances[sender][msg.sender] -= amount; 74 | 75 | emit Transfer(sender, recipient, amount); 76 | return true; 77 | } 78 | 79 | // Check how much a spender is allowed to spend on behalf of an owner 80 | function allowance(address owner, address spender) public view override returns (uint256) { 81 | return _allowances[owner][spender]; 82 | } 83 | 84 | // Mint new tokens (only the contract owner can mint tokens) 85 | function mint(uint256 amount) public onlyOwner { 86 | _totalSupply += amount * (10 ** uint256(decimals)); 87 | _balances[owner] += amount * (10 ** uint256(decimals)); 88 | emit Transfer(address(0), owner, amount * (10 ** uint256(decimals))); 89 | } 90 | 91 | // Burn tokens (destroy tokens from the owner's balance) 92 | function burn(uint256 amount) public onlyOwner { 93 | require(_balances[owner] >= amount, "Insufficient balance to burn"); 94 | _totalSupply -= amount * (10 ** uint256(decimals)); 95 | _balances[owner] -= amount * (10 ** uint256(decimals)); 96 | emit Transfer(owner, address(0), amount * (10 ** uint256(decimals))); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /linea.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.17; 3 | 4 | contract Linea { 5 | 6 | address public owner; 7 | 8 | constructor() { 9 | owner = msg.sender; 10 | } 11 | 12 | 13 | modifier onlyOwner() { 14 | require(msg.sender == owner, "not an owner!"); 15 | _; 16 | } 17 | 18 | string public greet = "Hello from Phratry DAO"; 19 | 20 | function pay() external payable {} 21 | 22 | function withdraw() external onlyOwner { 23 | payable(msg.sender).transfer(address(this).balance); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /monad.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | // ERC20 standard interface 5 | interface IERC20 { 6 | function totalSupply() external view returns (uint256); 7 | function balanceOf(address account) external view returns (uint256); 8 | function transfer(address recipient, uint256 amount) external returns (bool); 9 | function allowance(address owner, address spender) external view returns (uint256); 10 | function approve(address spender, uint256 amount) external returns (bool); 11 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 12 | 13 | event Transfer(address indexed from, address indexed to, uint256 value); 14 | event Approval(address indexed owner, address indexed spender, uint256 value); 15 | } 16 | 17 | contract LoyaltyPoints is IERC20 { 18 | string public name = "LoyaltyPoints"; 19 | string public symbol = "LPT"; 20 | uint8 public decimals = 18; 21 | uint256 private _totalSupply; 22 | 23 | mapping(address => uint256) private _balances; 24 | mapping(address => mapping(address => uint256)) private _allowances; 25 | 26 | address public owner; 27 | 28 | modifier onlyOwner() { 29 | require(msg.sender == owner, "Only the contract owner can perform this action"); 30 | _; 31 | } 32 | 33 | constructor(uint256 initialSupply) { 34 | owner = msg.sender; // Contract deployer becomes the owner 35 | _totalSupply = initialSupply * (10 ** uint256(decimals)); 36 | _balances[owner] = _totalSupply; 37 | emit Transfer(address(0), owner, _totalSupply); 38 | } 39 | 40 | // Total supply of the token 41 | function totalSupply() public view override returns (uint256) { 42 | return _totalSupply; 43 | } 44 | 45 | // Check balance of an account 46 | function balanceOf(address account) public view override returns (uint256) { 47 | return _balances[account]; 48 | } 49 | 50 | // Transfer tokens between accounts 51 | function transfer(address recipient, uint256 amount) public override returns (bool) { 52 | require(_balances[msg.sender] >= amount, "Insufficient balance"); 53 | _balances[msg.sender] -= amount; 54 | _balances[recipient] += amount; 55 | emit Transfer(msg.sender, recipient, amount); 56 | return true; 57 | } 58 | 59 | // Allowance: Check how much a spender is allowed to spend from the owner's balance 60 | function allowance(address owner, address spender) public view override returns (uint256) { 61 | return _allowances[owner][spender]; 62 | } 63 | 64 | // Approve a spender to spend tokens on behalf of the owner 65 | function approve(address spender, uint256 amount) public override returns (bool) { 66 | _allowances[msg.sender][spender] = amount; 67 | emit Approval(msg.sender, spender, amount); 68 | return true; 69 | } 70 | 71 | // Transfer tokens from one account to another using an approved allowance 72 | function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { 73 | require(_balances[sender] >= amount, "Insufficient balance"); 74 | require(_allowances[sender][msg.sender] >= amount, "Allowance exceeded"); 75 | 76 | _balances[sender] -= amount; 77 | _balances[recipient] += amount; 78 | _allowances[sender][msg.sender] -= amount; 79 | 80 | emit Transfer(sender, recipient, amount); 81 | return true; 82 | } 83 | 84 | // Mint new tokens (only the owner can mint new tokens) 85 | function mint(uint256 amount) public onlyOwner { 86 | _totalSupply += amount * (10 ** uint256(decimals)); 87 | _balances[owner] += amount * (10 ** uint256(decimals)); 88 | emit Transfer(address(0), owner, amount * (10 ** uint256(decimals))); 89 | } 90 | 91 | // Burn tokens (destroy tokens from owner's balance) 92 | function burn(uint256 amount) public onlyOwner { 93 | require(_balances[owner] >= amount, "Not enough tokens to burn"); 94 | _totalSupply -= amount * (10 ** uint256(decimals)); 95 | _balances[owner] -= amount * (10 ** uint256(decimals)); 96 | emit Transfer(owner, address(0), amount * (10 ** uint256(decimals))); 97 | } 98 | } 99 | --------------------------------------------------------------------------------