Skip to content

Instantly share code, notes, and snippets.

View imqdee's full-sized avatar

John imqdee

View GitHub Profile

Keybase proof

I hereby claim:

  • I am qd-qd on github.
  • I am qdqd (https://keybase.io/qdqd) on keybase.
  • I have a public key whose fingerprint is 4028 6901 E0CC 8408 4D0C CB48 FF52 7DD6 9A95 D50E

To claim this, I am signing this object:

This RPC call works great when using a bundler not managed by Alchemy. However, an error is triggered when using your bundler.

cast rpc eth_estimateUserOperationGas "{\"sender\":\"0x80b86933313237be38B9E87dDbe99865A12c8ddd\",\"nonce\":\"0x0\",\"initCode\":\"0x29e69af6083f790d31804ed9adad40ccc32accc9af09872500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000120728da5b63228c33d0f2e2797ee87fda099a2795a31831d5e8f406a4a8be80ad4000000000000000000000000000000000000000000000000000000000000009849960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97635d00000000fbfc3007154e4ecc8c0b6e020557d7bd0014f4da2a72a853013e7a71eab983e798c0d3e190c6a5010203262001215820551be8f48a4b2d77a8cf8fe565fd8644c77f44aef04099b6764acf668a5dea0f225820e92de8f6a8d71246b08f68a8cfc10de82ee97f51b4cd585d978a1097931fc7720000000000000000000000000000000000000000000000000000000000000000000000000000004200f7aabdbddb526bb02fc3a1138ae375236d229c571509109d5ba7d5dd1591c6c058c
contract Deployer {
event Deployed(address);
// This is the runtime code of the contract we would like to deploy
// Example: `contract DummyContract { uint256 public nonce; }`
bytes CONTRACT_RUNTIME_CODE =
hex"6080604052348015600e575f80fd5b50600436106026575f3560e01c8063affed0e014602a575b5f80fd5b60315f5481565b60405190815260200160405180910390f3";
// This handmade creation code is responsible of returning the creation code of dynamic length
// ⚠️ It assumes the contract we would like to deploy doesn't have a constructor (!!)

Cast overview

Play with the following cast commands

  • Convert an UTF8 text to hexidecimal
  • Convert an ETH amount into wei
  • Convert wei into an ETH amount
  • Get the zero hash
  • Get the zero address
  • Get the maximum value of a uint256 type
@imqdee
imqdee / hardhat-abitrary-bytecode-deployment.ts
Created March 8, 2023 16:44
Just a test that deploy an arbitrary bytecode
import { expect } from "chai";
import { ethers } from "hardhat";
describe("off-chain arbitrary code deployment", function () {
it("test everything goes well", async function () {
// get the signer available in the test environment
const [deployer] = await ethers.getSigners();
// define the bytecode I wanna deploy. After the construction step, only
// this bytecode will be stored as the contract's code
@imqdee
imqdee / stack-too-deep.sol
Created February 28, 2023 13:32
Easy to implement solutions for the StackTooDeep error
pragma solidity >=0.8.19;
contract Test {
// This function raise a "Stack too deep" error
// The explanation for this is due to the constraints of referencing
// variables in the EVM stack. Despite the possibility of having over
// 16 variables in the stack, any attempt to reference a variable beyond slot
// 16 will result in failure. Hence, it can be difficult to identify the exact
// reason for a code's failure, and sometimes making random alterations may appear
// to resolve the issues
@imqdee
imqdee / ledger-fresh-article.md
Created December 29, 2022 14:01
Ledger Fresh Article

Ledger Fresh

Why Ledger Fresh?

Things to know:

  • The Ledger Innovation Lab is our team of experts dedicated to exploring new ideas and solving pain points for users interacting with the Ledger ecosystem.
  • The Innovation Lab’s latest project is called Ledger Fresh.
@imqdee
imqdee / Account.json
Last active December 19, 2022 13:51
Starknet PoC deployer artifacts
This file has been truncated, but you can view the full file.
{
"abi": [
{
"members": [
{
"name": "to",
"offset": 0,
"type": "felt"
},
{

Building an NFT API with filtering, sorting, relationships, and full text search with The Graph.

In this workshop we'll build a subgraph for querying NTF data from the Metroverse City Block smart contract, implementing queries for fetching NFTs as well as their owners, building relationships between them, full text search, sorting, and filtering.

The codebase for this project is located here

Prerequisites

To be successful in this tutorial, you should have Node.js installed on your machine. These days, I recommend using either nvm.

@imqdee
imqdee / generic.org
Created January 25, 2022 10:43 — forked from hrkrshnn/generic.org
Some generic writeup about common gas optimizations, etc.

Upgrade to at least 0.8.4

Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!

The advantages of versions 0.8.* over <0.8.0 are:

  • Safemath by default from 0.8.0 (can be more gas efficient than some library based safemath.)
  • Low level inliner from 0.8.2, leads to cheaper runtime gas. Especially relevant when the contract has small functions. For