Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 { Layout, plot, Plot } from 'nodeplotlib'; | |
import { readFileSync } from 'fs'; | |
(async () => { | |
let readVal = readFileSync('eips.json', { | |
encoding: "utf-8" | |
}); | |
const eips = JSON.parse(readVal); |
This file contains 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
// hardhat task | |
task('blockTimestamp', 'Prints the block timestamp', async (_, { ethers }) => { | |
const currentBlock = await ethers.provider.getBlockNumber(); | |
const blockTimestamp = (await ethers.provider.getBlock(currentBlock)).timestamp; | |
console.log(blockTimestamp); | |
const date = new Date(blockTimestamp * 1000); // Date requires ms, whereas block.timestamp is in s | |
console.log(date) | |
}); |
This file contains 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
// In https://solidity-by-example.org/sending-ether/ | |
// They say: call in combination with re-entrancy guard is the recommended method to use after December 2019. | |
// (see https://consensys.github.io/smart-contract-best-practices/recommendations/#dont-use-transfer-or-send for an explanation) | |
// and compare the gas fees of the 3 methods: | |
// transfer (2300 gas, throws error) | |
// send (2300 gas, returns bool) | |
// call (forward all gas or set gas, returns bool) | |
// I tested all 3 methods, by sending 10 eth to a contract and then withdrawing using these functions: |
This file contains 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 test(uint256 a) public pure returns (uint256) { | |
uint256 fooERROR = 2 * 997 / 1000; // ERROR: Type rational_const 997 / 500 is not implicitly convertible to expected type uint256. Try converting to type ufixed16x3 or use an explicit conversion. | |
uint256 fooOK = a * 997 / 1000; // this works... somehow | |
uint256 fooERROR2 = a * (997 / 1000); // Operator * not compatible with types uint256 and rational_const 997 / 1000 | |
} |
This file contains 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.7.0 <0.9.0; | |
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "hardhat/console.sol"; | |
contract cEth is IERC20, Ownable { |
This file contains 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
// This is the basic scaffold-eth contract. Note the SetPurpose event :) | |
pragma solidity >=0.8.0 <0.9.0; | |
import "hardhat/console.sol"; | |
contract YourContract { | |
// `indexed` is necessary to filter! | |
event SetPurpose(address sender, string indexed purpose); |
This file contains 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 { ethers, deployments, network } from "hardhat"; | |
async function main() { | |
const acct = (await ethers.provider.listAccounts())[0]; | |
const signer = (await ethers.getSigners())[0]; | |
const greeterAddress = (await deployments.get("Greeter")).address; | |
const Greeter = await ethers.getContractFactory("Greeter"); | |
const greeter = Greeter.attach(greeterAddress); |
This file contains 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 performLongTask(cb: (err:any, res: any) => any) { | |
const returnValue = 42; | |
setTimeout(() => cb(null, returnValue), 3000) | |
} | |
performLongTask((err, res) => { | |
if (err) throw new Error('we got an error'); | |
console.log("callback:", res) | |
}) |
This file contains 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 fs from "fs"; | |
const n = 5000000; | |
const s = []; | |
for (let i = 0; i < n; i++) { | |
s.push({ | |
idx: i, | |
}); | |
} |
OlderNewer