This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clone(address implementation) internal returns (address instance) { | |
assembly { | |
let ptr := mload(0x40) | |
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) | |
mstore(add(ptr, 0x14), shl(0x60, implementation)) | |
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) | |
instance := create(0, ptr, 0x37) | |
} | |
require(instance != address(0), "ERC1167: create failed"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract HelloWorld { | |
function showMessage() public pure returns (string memory) { | |
return "Hello, World!"; | |
} | |
} | |
contract HelloWorldFactory { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
contract HelloWorld { | |
function showMessage() public pure returns (string memory) { | |
return "Hello, World!"; | |
} | |
} | |
contract HelloWorldFactory { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.17; | |
library Factorial { | |
function factorial(uint n) public pure returns (uint) { | |
uint result = 1; | |
for (uint i = 1; i <= n; i++) { | |
result *= i; | |
} | |
return result; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./Factorial.sol"; | |
contract FactorialCalculator { | |
using Factorial for uint; | |
uint public factorial; | |
constructor(uint n) public { | |
factorial = n.factorial(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
contract DemoFallbackFunctions { | |
event Log(string typeOfFunction, uint gas); | |
// Fallback function must be declared as external. | |
fallback() external payable { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
// NOTE: Deploy this contract first | |
contract IronMan { | |
uint public power; | |
uint public speed; | |
uint public impact; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.9; | |
contract PrivateAccessDemo { | |
uint256 private privateVariable; | |
uint256 public publicVariable; | |
constructor(uint256 privateValue, uint256 publicValue) { | |
privateVariable = privateValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.7; | |
contract DemoCustomError { | |
error Unauthorized(); | |
error myCustomError(string message); | |
address public owner = address(0x0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.7; | |
contract DemoErrors { | |
function demoRequire(uint input) public pure { | |
require(input > 5, "input must be greater than 5"); | |
} | |
function demoRevert(uint input) public pure { |
NewerOlder