Skip to content

Instantly share code, notes, and snippets.

View casweeney's full-sized avatar
👨‍💻
Building Platforms

Coding Cas casweeney

👨‍💻
Building Platforms
View GitHub Profile
@casweeney
casweeney / Staking.sol
Last active August 4, 2022 16:51
Staking Contract
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
contract Staking {
event Stake(address user, uint amount);
uint256 deadline = block.timestamp + 5 minutes;
mapping(address => uint) balances;
@casweeney
casweeney / StakingAssignment.sol
Created August 1, 2022 12:43
Assignment given by Kevin at Web3Bridge
// Collect funds in a payable `stake()` function and track individual `balances` with a mapping:
// ( Make sure to add a `Stake(address,uint256)` event and emit)
// After some `deadline` allow anyone to call an `execute()` function
// If the deadline has passed and the threshold is met, it should call `exampleExternalContract.complete{value: address(this).balance}()`
@casweeney
casweeney / Counter.sol
Last active August 1, 2022 17:55
Class Test
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
contract Counter {
uint256 count;
uint256 restrictionTime = block.timestamp + 30;
function add() public {
require(block.timestamp < restrictionTime, "restriction time reached");
@casweeney
casweeney / CustomErrorNatspec.sol
Created August 1, 2022 17:52
Using custom errors with NATSPEC
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
/// ogbeni
error Unauthorized();
/// @custom:experimental This is an experimental contract.
contract VendingMachine {
address payable owner = payable(msg.sender);
@casweeney
casweeney / KokocodesCount.sol
Created August 1, 2022 17:56
Count implementation by Koko codes
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;
// create a timer for increement and decreement but they should only work after 30secs
contract counter {
uint256 count;
uint256 lastRun;
function add() external {
@casweeney
casweeney / JesseCountRestriction.sol
Created August 1, 2022 17:58
Jesserc Implementation
// SPDX-License-Identifier: MIT;
pragma solidity ^0.8.7;
contract Counter{
uint public count;
uint timer = 0;
error timeNotReached(string);
bool reached = false;
@casweeney
casweeney / TypeCasting.sol
Created August 2, 2022 23:04
Contract to typecast bytes32 to string
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TypeCasting {
bytes32 public x = "This is the beginning of Adddddd";
string public y = "This is the beginning of Adddddd";
function convertByteToString() public view returns(string memory) {
string memory result = string(abi.encodePacked(x));
return result;
@casweeney
casweeney / RevisionStake.sol
Last active August 4, 2022 21:50
Class revision
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
contract RevStake {
event Stake(address sender, uint256 value);
mapping(address => uint) balances;
uint deadline = block.timestamp + 5 minutes;
@casweeney
casweeney / btyesmanager.sol
Created August 3, 2022 15:02 — forked from developeruche/btyesmanager.sol
Explains Bytes Code and Init Code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract ByteCodeManager {
function getBytecode(address _owner, uint _foo) public pure returns (bytes memory) {
bytes memory bytecode = type(TestContract).creationCode;
return abi.encodePacked(bytecode, abi.encode(_owner, _foo));
}
@casweeney
casweeney / SecondTest.sol
Last active August 4, 2022 16:58
This is the a second test at Web3Bridge Cohort VII
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
contract Deposit {
mapping(address => uint) balances;
function deposit() public payable {
require(msg.value > 0, "No value sent");
balances[msg.sender] += msg.value;