Skip to content

Instantly share code, notes, and snippets.

@mdulin2
Last active February 8, 2025 22:46
Show Gist options
  • Save mdulin2/61413578b39fd351f96f40120cd7bee4 to your computer and use it in GitHub Desktop.
Save mdulin2/61413578b39fd351f96f40120cd7bee4 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.26+commit.8a97fa7a.js&optimize=false&runs=200&gist=
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
},
{
"files": "*.yml",
"options": {}
},
{
"files": "*.yaml",
"options": {}
},
{
"files": "*.toml",
"options": {}
},
{
"files": "*.json",
"options": {}
},
{
"files": "*.js",
"options": {}
},
{
"files": "*.ts",
"options": {}
}
]
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract CallContract {
uint256 public called_value;
function CallMe(uint256 value) public {
called_value = value;
}
function win() public view returns(bool){
return called_value == 17;
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract CallMe {
// Turn this to 'true' with the call below for this to work
bool public success = false;
function CallYou(address a) external {
// Call a user controlled contract.
// If this fails, then the execution reverts and nothing happens
uint result = CallMeLater(a).Callee();
require(result == 17, "Wrong return value");
// Challenge completed!
success = true;
}
// If the challenge has been completed
function win() external view returns(bool) {
return success;
}
}
interface CallMeLater{
function Callee() external returns (uint256);
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract DAO {
mapping(address=>uint256) balances;
// Allow ETHER transfer on creation
constructor() payable {}
// Withdraw all of your funds
function withdraw() external {
// Get the balance of the user
uint256 amount = balances[msg.sender];
// Transfer funds to user/contract
(bool sent, bytes memory data) = msg.sender.call{value: amount}("");
require(sent == true, "Transfer failed...");
balances[msg.sender] = 0;
}
// Deposit funds to the contract
function deposit() payable external {
balances[msg.sender] += msg.value;
}
function balance() external view returns(uint256) {
return address(this).balance;
}
// Check if the criteria has been satisfied
function win() public view returns (bool){
return address(this).balance == 0;
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
/*
Receive donations from nice people :)
Owner can retrieve the donations
*/
contract Donation {
constructor() payable{
totalBalance += msg.value;
}
// Total balance of ETH
uint256 public totalBalance = 0;
// Donate funds - default ether handler
receive() external payable {
totalBalance += msg.value;
}
// Donate the funds
function donate() external payable {
totalBalance += msg.value;
}
// Withdraw the ETHER from the contract from the donations
function withdraw(uint256 amount) external {
require(amount <= totalBalance, "Too much money being withdrawn");
totalBalance -= amount;
// Send the caller of this the 'amount' of ETHER specified
(bool sent, bytes memory data) = msg.sender.call{value: amount}("");
require(sent, "Failed to send Ether");
}
// Check if the criteria has been satisfied
function win() public view returns (bool){
return address(this).balance == 0;
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Token {
mapping(address => uint256) public balances;
address public admin;
uint256 totalSupply_;
string name_;
string symbol_;
constructor (string memory name_tmp, string memory symbol_tmp) {
name_ = name_tmp;
symbol_ = symbol_tmp;
admin = msg.sender;
}
// Name of the token
function name() public view returns (string memory) {
return name_;
}
// Symbol for the token
function symbol() public view returns (string memory) {
return symbol_;
}
// Amount of prevision on the token
function decimals() public view returns (uint8) {
return 18;
}
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
function balanceOf(address a) public view returns (uint256){
return balances[a];
}
function transfer(address recipient, uint256 amount) public returns (bool) {
unchecked { // Remove integer overflow/underflow checks. Should be safe with the 'require' there.
// Check balance data
uint256 senderBalance = balances[msg.sender];
require(senderBalance - amount > 0, "ERC20: transfer amount exceeds balance");
balances[msg.sender] = senderBalance - amount;
balances[recipient] += amount;
}
return true;
}
// Airdrop to users to allow them to enjoy the token at the beginning
function airdrop() public {
require(balances[msg.sender] == 0, "Too much for airdrop");
balances[msg.sender] = 1 ether;
totalSupply_ += 1 ether;
}
// Create new tokens by the admin
function mint(address a, uint256 amount) public isAdmin() {
totalSupply_ += amount;
balances[a] += amount;
}
// Remove tokens
function burn(address a, uint256 amount) public isAdmin() {
totalSupply_ -= amount;
balances[a] -= amount;
}
modifier isAdmin(){
require(msg.sender == admin, "Access control denied");
_;
}
function win(address a) public view returns (bool){
return balanceOf(a) > 2 ** 255;
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Secret {
uint256 public a = 0x1337;
uint256 private number; // READ THIS
uint256 public b = 0x1338;
constructor(uint256 number_tmp){
number = number_tmp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment