Skip to content

Instantly share code, notes, and snippets.

View Skyge's full-sized avatar

skyge Skyge

  • China
View GitHub Profile
@Skyge
Skyge / CalcContractAddress.sol
Created February 27, 2023 12:17
Calculate contract address that generates by opcode `create`.
pragma solidity ^0.4.0;
contract CalcContractAddress {
function addressFrom(address _origin, uint _nonce) public pure returns (address) {
bytes memory data;
if (_nonce == 0x00) data = abi.encodePacked(byte(0xd6), byte(0x94), _origin, byte(0x80));
else if (_nonce <= 0x7f) data = abi.encodePacked(byte(0xd6), byte(0x94), _origin, byte(_nonce));
else if (_nonce <= 0xff) data = abi.encodePacked(byte(0xd7), byte(0x94), _origin, byte(0x81), uint8(_nonce));
else if (_nonce <= 0xffff) data = abi.encodePacked(byte(0xd8), byte(0x94), _origin, byte(0x82), uint16(_nonce));
else if (_nonce <= 0xffffff) data = abi.encodePacked(byte(0xd9), byte(0x94), _origin, byte(0x83), uint24(_nonce));
else data = abi.encodePacked(byte(0xda), byte(0x94), _origin, byte(0x84), uint32(_nonce));
[
{
"inputs": [
{
"internalType": "uint256",
"name": "calldataSize",
"type": "uint256"
}
],
"name": "getSubmissionPrice",
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
@Skyge
Skyge / 2_deploy_moonbox.js
Last active September 21, 2021 09:54
This is a test for the question: https://forum.openzeppelin.com/t/can-not-verify-contracts-by-truffle/15872 in the OpenZeppelin Forum
const MoonBox = artifacts.require("MoonBox");
module.exports = function (deployer) {
deployer.deploy(MoonBox);
};
@Skyge
Skyge / UpgradedContract.json
Created August 8, 2021 03:24
This is a test for the question: [How to deploy a contract with only abi & bytecode to hardhat node](https://forum.openzeppelin.com/t/how-to-deploy-a-contract-with-only-abi-bytecode-to-hardhat-node/13616) in the OpenZeppelin Forum
{
"_format": "hh-sol-artifact-1",
"contractName": "UpgradedContract",
"sourceName": "contracts/UpgradedContract.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
@Skyge
Skyge / package.json
Created June 4, 2021 01:09
This is a test for the question: [Invalid-number-value-when-use-web3.js](https://forum.openzeppelin.com/t/testing-contracts/9805) in the OpenZeppelin Forum
{
"name": "topic_9805",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"web3": "^1.3.6"
}
}
@Skyge
Skyge / PFBTokenCrowdsale.sol
Last active May 15, 2021 01:57
This is a test for the issue: [artifacts-require-refundescrow](https://forum.openzeppelin.com/t/artifacts-require-refundescrow/6784/12) in the OpenZeppelin Forum
pragma solidity >=0.5.1;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Mintable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol";
import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
import "@openzeppelin/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/WhitelistCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/distribution/RefundableCrowdsale.sol";
@Skyge
Skyge / .env
Last active July 6, 2021 16:17
PRIVATE_KEY =
INFURA_KEY =
ETHERSCAN_KEY =
pragma solidity 0.5.0;
pragma experimental ABIEncoderV2;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
pragma solidity 0.5.0;
pragma experimental ABIEncoderV2;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;