Skip to content

Instantly share code, notes, and snippets.

View grsLammy's full-sized avatar
💻
Working from home

Gulam Rasul Shah grsLammy

💻
Working from home
View GitHub Profile
// Code snippet for eth-JSON RPC method
import axios from "axios";
import { MATIC_RPC_URL } from "../utils/constants";
// Fetch finality data using eth-JSON RPC method
export async function ethJsonRpcMethod(yourBlock: number): Promise<void> {
try {
console.log("Waiting for your block to get finalized...\n");
// Flag for block finality
let finalised: boolean = false;
@grsLammy
grsLammy / placeSingleOrderController.ts
Created November 3, 2023 10:05
Code snippet for single order
export const placeSingleOrderController = async (
req: ClientWithRequestQueryBody<{ projectId: string }, { qty: number; price: number }>,
res: Response,
) => {
try {
const { projectId } = req.query;
const { qty, price } = req.body;
const order = {
category: 'spot',
@grsLammy
grsLammy / withdrawExitMATIC.ts
Created October 5, 2023 11:47
withdraw MATIC from L2 to L1 and withdraw exit from L1
import { sleep } from "../utils/utilityFunctions";
import { getPlasmaClient } from "../utils/plasmaClient";
import { maticAddressL1 } from "../../config";
import { ITransactionWriteResult } from "@maticnetwork/maticjs";
import { PlasmaClient } from "@maticnetwork/maticjs-plasma";
import type { ERC20 } from "@maticnetwork/maticjs-plasma/dist/ts/erc20";
import ps from "prompt-sync";
const prompt = ps();
export async function withdrawExitMATIC() {
@grsLammy
grsLammy / depositMATIC
Created October 5, 2023 11:45
deposit MATIC from L1 to L2 using maticjs-plasma
import { sleep } from "../utils/utilityFunctions";
import { getPlasmaClient } from "../utils/plasmaClient";
import { getChildUser, maticAddressL1 } from "../../config";
import { ITransactionWriteResult } from "@maticnetwork/maticjs";
import { PlasmaClient } from "@maticnetwork/maticjs-plasma";
import type { ERC20 } from "@maticnetwork/maticjs-plasma/dist/ts/erc20";
import ps from "prompt-sync";
const prompt = ps();
export async function depositMATIC() {
@grsLammy
grsLammy / getPlasmaClient.ts
Created October 5, 2023 11:44
setup plasma client
import {
getRootUser,
getChildUser,
getPrivateKeyGoerli,
getInfuraProjectId,
getPrivateKeyMumbai,
} from "../../config";
import { use } from "@maticnetwork/maticjs";
import HDWalletProvider from "@truffle/hdwallet-provider";
import { PlasmaClient } from "@maticnetwork/maticjs-plasma";
@grsLammy
grsLammy / log.json
Created October 3, 2023 11:45
log for the Heimdal API 50 Milestone Finality
[
{
"index": 1,
"milestone_id": "905ecdf5-5d5b-46c2-ae7c-0afe96433975 - 0xa7f58370bed9b19598480fe25a9cadc37ad19f3c",
"totalTime": "0 min and 46 sec"
},
{
"index": 2,
"milestone_id": "249ada97-51a2-4e06-ba72-fa7be6112fe8 - 0x72a247cc589ed37c8742fc75b1149149d13d1443",
"totalTime": "5 min and 10 sec"
@grsLammy
grsLammy / constants.ts
Created October 3, 2023 11:42
code snippet for performance testing and logging of Heimdal API for Milestone finality
export const MILESTONE_API = "https://heimdall-api-testnet.polygon.technology/milestone/latest";
@grsLammy
grsLammy / erc20TransferFrom.ts
Last active October 18, 2023 10:51
Best practices for transaction management
const erc20TransferFrom = async () => {
try {
/* ---------------------------- SETUP ------------------------------ */
/*
USING INFURA PROVIDER
*/
const provider: ethers.providers.InfuraProvider =
new ethers.providers.InfuraProvider('maticmum', infuraProjectID);