Skip to content

Instantly share code, notes, and snippets.

View elmariachi111's full-sized avatar
🦄
meow

Stefan Adolf elmariachi111

🦄
meow
View GitHub Profile
@elmariachi111
elmariachi111 / useInitiateAuction.tsx
Created September 15, 2023 07:37
rewrite useInitiateAuction for wagmi
'use client'
import { getUnixTime, sub } from 'date-fns'
import { useCallback, useState } from 'react'
import { Address, decodeErrorResult, toHex, zeroAddress } from 'viem'
import { abi } from '@/lib/abi/EasyAuction'
import { useEasyAuctionInitiateAuction } from '@/lib/generated/wagmi/contracts'
import { Transaction } from '@/types/chain'
import { BID_CANCEL_DEADLINE_INTERVAL_HOURS } from '@/utils/auction'
import { currentChain, safeDecodeLogs } from '@/utils/chain'
@elmariachi111
elmariachi111 / gist:9dd638db2e757586943a96fa98ecae5d
Created March 21, 2023 22:50
Chatgpt render and export p5 image
Stefan Adolf
Write a JavaScript program that renders a p5js image of a flower inside a browser context
Sure, here's an example of how to render a flower using p5js in a browser context:
html
Copy code
<!DOCTYPE html>
<html>
<head>
@elmariachi111
elmariachi111 / Vesting.sol
Created March 21, 2023 22:24
Gpt4 token vesting
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract MultiBeneficiaryVestingToken {
using SafeMath for uint256;
struct VestingSchedule {
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
@elmariachi111
elmariachi111 / OneOnOneNFT.sol
Last active April 8, 2022 17:42
OneOnOneNFT.sol
// contracts/Splice.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import '@openzeppelin/contracts/utils/math/SafeMath.sol';
contract OneOnOneNFTMarketPlace {
using SafeMath for uint256;
struct RoyaltyReceiver {
@elmariachi111
elmariachi111 / Web3ModalContext.tsx
Last active March 19, 2022 09:18
A React Context to activate Web3Modal & expose provider, signer and account
import { providers } from "ethers";
import React, { useContext, useEffect, useState } from "react";
import WalletConnectProvider from "@walletconnect/web3-provider";
import { ethers } from "ethers";
import Web3Modal from "web3modal";
interface IWeb3Context {
provider?: providers.Web3Provider;
signer?: ethers.Signer;
account?: string;
@elmariachi111
elmariachi111 / traits.js
Created February 25, 2022 11:37
create NFT traits with given probability
function generateTrait(trait_type, distributions, values) {
const sum = distributions.reduce((prv,cur) => (cur + prv), 0);
if (sum !== 10000) throw ("probabilites don't add up to 100%");
const traitRandomness = 10000 * p5.random();
let probability = 10000;
for (const i in distributions) {
probability -= distributions[i]
if (traitRandomness > probability) {
return { trait_type, value: values[i] }
}
@elmariachi111
elmariachi111 / splice_subgraph.ts
Created December 13, 2021 11:17
subgraph mapping for Splice mints
import { ERC721 as ERC721Contract } from '../generated/Splice/ERC721';
import { Bytes, ByteArray, ethereum } from '@graphprotocol/graph-ts';
import { Splice, Style } from '../generated/schema';
import { Minted, Splice as SpliceContract } from '../generated/Splice/Splice';
export function handleMinted(event: Minted): void {
const tokenId = event.params.token_id.toString();
const splice = new Splice(tokenId);
const spliceContract = SpliceContract.bind(event.address);
@elmariachi111
elmariachi111 / interactWithStroage.js
Last active October 21, 2021 14:58
Storage Interaction
const { ethers } = require("ethers");
const abi = require("./storage.abi.json");
const INFURA_KEY = "..."; //get at https://infura.io/product/ethereum
const CONTRACT_ADDRESS = "0x7DA77f8a834369dDc5e9e47407C9746Ed55C3b72";
const provider = new ethers.providers.InfuraProvider(42, INFURA_KEY);
const contract = new ethers.Contract(CONTRACT_ADDRESS, abi, provider);
(async function main() {
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{