Skip to content

Instantly share code, notes, and snippets.

@samlaf
samlaf / transfer-vs-send-vs-call.sol
Last active March 11, 2022 21:07
Sending Ether (transfer, send, call)
// 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:
@samlaf
samlaf / latest-block-timestamp-in-date-format.txt
Last active October 1, 2024 03:26
Get ethereum latest block timestamp in date format
// 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)
});
@samlaf
samlaf / plot.ts
Created December 6, 2021 16:04
Plot the number of eips published per year
import { Layout, plot, Plot } from 'nodeplotlib';
import { readFileSync } from 'fs';
(async () => {
let readVal = readFileSync('eips.json', {
encoding: "utf-8"
});
const eips = JSON.parse(readVal);
@samlaf
samlaf / make_plots.ipynb
Last active November 21, 2020 02:31
Hypothesis Testing widgets
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.