Skip to content

Instantly share code, notes, and snippets.

import { encodeAbiParameters, toHex, isHex, parseAbiParameters, zeroAddress, Hex } from "viem";
import { keccak256, toBytes } from "viem";
import { extractPublicKey } from '@metamask/eth-sig-util';
import { pubToAddress } from "@ethereumjs/util";
import { fetchCred } from "@phi/protocol/fetch/cred";
import { fetchVerifierList, isVerifierResponse } from "@phi/protocol/verifier";
import { fetchArtMetadata } from "@phi/protocol/fetch/factory";
import { CredType, Verifier } from "@phi/protocol/types";
import { createSignature } from "@phi/protocol/signature";
import { Irys } from "@phi/services/irys/client";
type Credential = {
id: number;
votes: number;
art: boolean;
};
function getQualifiedCredentials(
credentials: Credential[],
prevThreshold: number,
prevMedianVotes: number,
import axios from "axios";
import { ethers } from "ethers";
import fs from "fs";
import WawaNFT from "../lambda-fn/utility/abi/WawaNFT.json";
async function fetchMetadata() {
const provider = new ethers.providers.AlchemyProvider("homestead", "<ALCHEMY_API_KEY_ETH>");
const contractAddress = "0x2d9181b954736971bb74043d4782dfe93b55a9af";
import { secretId } from "@env";
import { successResponse } from "@object-helpers/apiResponse";
import { createCoupon, generateHashBuffer, serializeCoupon } from "@object-helpers/coupons";
import { getSigKeyfromKMS } from "@utility/getSigKeyfromKMS";
import { simpleRateLimit } from "@utility/rateLimiter";
import { getSecret } from "@utility/secret";
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import axios from "axios";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { secretId } from "@env";
import { notVerifyResponse, successResponse } from "@object-helpers/apiResponse";
import { createCoupon, generateHashBuffer, serializeCoupon } from "@object-helpers/coupons";
import { getSecret } from "@object-helpers/phiUtils";
import { getSigKeyfromKMS } from "@utility/getSigKeyfromKMS";
import { simpleRateLimit } from "@utility/rateLimiter";
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import axios from "axios";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
// Updated 2023/5/3
// This note is a memo to share the method of verifying quest objects.
// If any correction is needed in the logic, please contact the PHI team.
-------------- PHI --------------
// Related Contract links
// PhiMap: '0xe8b6395d223C9D3D85e162f2cb2023bC9088a908',
// Polygonscan: https://polygonscan.com/address/0xe8b6395d223C9D3D85e162f2cb2023bC9088a908
// Registry: '0x6532B97295a0728880AE81D5CD7248f32E24e39a',
const abi = [
{
stateMutability: "view",
type: "function",
name: "pool_count",
inputs: [],
outputs: [
{
name: "",
type: "uint256",
import { targetEnv, isLocal } from "../env";
import { getCache, putCache } from "./ddbCache";
const TABLE_NAME = "cache-" + targetEnv;
const DEFAULT_TTL = 90000;
export type CachedContractCallOptions = {
tableName?: string;
ttl?: number;
toJson?: boolean;
import { sha3 } from "web3-utils";
import contractAbi from "./abi/ENS.json";
const namehash = require("@ensdomains/eth-ens-namehash");
// Config
/* -------------------------------------------------------------------------- */
const secretkey ="<0x123456>"
const INFURA_API_KEY ="<aaaaa>"
// Definitely long strings (ex. phiphi0320102081028) causes this problem 0x problem.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/// @title Voting with delegation.
contract Ballot {
// This declares a new complex type which will
// be used for variables later.
// It will represent a single voter.
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted