Skip to content

Instantly share code, notes, and snippets.

View PraneshASP's full-sized avatar
Building

Pranesh A S PraneshASP

Building
View GitHub Profile
@PraneshASP
PraneshASP / Test.t.sol
Last active February 13, 2024 05:11
Using Mesc in foundry tests to avoid hardcoding urls.
// See Mesc Reference for setup: https://github.com/paradigmxyz/mesc/tree/main/cli#reference
contract TestSetup is Test {
function fetchRpcUrlFromMesc(string memory networkName) internal returns (string memory url) {
string[] memory inputs = new string[](3);
inputs[0] = "mesc";
inputs[1] = "url";
inputs[2] = networkName;
@PraneshASP
PraneshASP / Counter.t.sol
Last active September 7, 2023 07:16
Foundry misleading error statement.
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.11;
import "forge-std/src/Test.sol";
contract Counter {
uint256 value = 10;
event Incremented(uint256 _value);
@PraneshASP
PraneshASP / SignedWadMath.t.sol
Last active August 16, 2023 15:32
Solmate `wadMul()` bug ~ Halmos
// Read more about this here: https://twitter.com/0xkarmacoma/status/1691251106561540097
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.15;
import "forge-std/Test.sol";
contract SignedWadMathAsm {
function wadMul(int256 x, int256 y) public pure returns (int256 r) {
/// @solidity memory-safe-assembly
@PraneshASP
PraneshASP / Commands.sh
Created May 15, 2023 16:08
Minimal Foundry project setup
#Credits: https://twitter.com/jtriley_eth/status/1653885929592090625
#make directories (can be anything)
mkdir src out lib
# specify the 'src', 'out', and 'lib directories under
# [profile.default]
vim foundry.toml
# add 'forge-std module to 'lib'
@PraneshASP
PraneshASP / createChannel.js
Created August 2, 2021 20:58
Used to create your channel on the EPNS
require("dotenv").config();
const Ipfs = require("nano-ipfs-store");
const ethers = require("ethers");
const epnsAbi = require("../abis/epnsAbi.json");
const daiAbi = require("../abis/daiAbi.json");
const { EPNS_PROXY_ADDRESS, PROVIDER } = require("../constants");
async function createChannel() {
const channelName = "News Channel";
@PraneshASP
PraneshASP / sendNotifications.js
Last active August 2, 2021 20:37
This script is used to send ethereum based push notifications.
require("dotenv").config();
const Ipfs = require("nano-ipfs-store"); // Used to spin up local ipfs node
const ethers = require("ethers");
const epnsAbi = require("../abis/epnsAbi.json");
const { EPNS_PROXY_ADDRESS, PROVIDER } = require("../constants");
async function newMessage(newsTitle, description) {
return await new Promise((resolve, reject) => {
const title = newsTitle;
const message = description;
@PraneshASP
PraneshASP / app.js
Created July 22, 2021 17:57
Basic rate limiter - In-memory implementation of NodeJS
const express = require("express");
const moment = require("moment");
const app = express();
const PORT = process.env.PORT || 5000;
app.use(express.json());
const MAX_ATTEMPTS = 3; // after which the account should be locked
const LOCK_WINDOW = 2; // in minutes
@PraneshASP
PraneshASP / Faucet.sol
Created July 10, 2021 19:18
Smart contract for a token faucet
// SPDX-License-Identifier: UNLISCENSED
pragma solidity ^0.8.4;
interface IERC20 {
/**
* @dev returns the tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
@PraneshASP
PraneshASP / createWallet.js
Last active March 12, 2024 11:51
Create a bitcoin wallet with this simple script.
//Import dependencies
const bip32 = require('bip32')
const bip39 = require('bip39')
const bitcoin = require('bitcoinjs-lib')
//Define the network
const network = bitcoin.networks.bitcoin //use networks.testnet for testnet
// Derivation path
const path = `m/49'/0'/0'/0` // Use m/49'/1'/0'/0 for testnet
@PraneshASP
PraneshASP / app.js
Last active March 5, 2021 16:02
price-alert
const express = require("express");
const app = express(); // Initialize an express instance
const PORT = process.env.PORT || 5000; // Define the port
app.use(express.json());
app.get("/", (req, res) => { // Health check endpoint (optional)
return res.json({ status: "Up and running" });
});