Skip to content

Instantly share code, notes, and snippets.

@ParsaAminpour
Created March 28, 2025 14:48
Show Gist options
  • Save ParsaAminpour/8cf4eb422c64745895fdc205db41966f to your computer and use it in GitHub Desktop.
Save ParsaAminpour/8cf4eb422c64745895fdc205db41966f to your computer and use it in GitHub Desktop.
Script for performing PRCP collection admin operations on the Abstract network.
import { program } from 'commander'
import * as dotenv from 'dotenv'
import chalk from "chalk";
import Web3, { Wallet, Web3BaseWalletAccount } from "web3";
import { ContractAbi, Contract } from 'web3';
import fs from "fs";
dotenv.config()
/*
Example Commands:
npx ts-node index.ts airdrop --address 0x0a3d0Ed8dF8a925Fa67A510AEdC5d99b20F1971E --amount 2 --cluster testnet
npx ts-node index.ts airdrop-all --file airdrop.json --cluster testnet
npx ts-node index.ts get balance --address 0x0a3d0Ed8dF8a925Fa67A510AEdC5d99b20F1971E --cluster testnet
npx ts-node index.ts add-to-whitelist --file whitelist.json --cluster testnet
*/
const PRCSR_ABI = JSON.parse(fs.readFileSync("./abi/PRCSR.json", "utf8")).abi;
let web3: Web3;
let prcsrContract: Contract<ContractAbi>;
let sender: Web3BaseWalletAccount;
const initSetup = async (cluster: "testnet" | "mainnet") => {
web3 = new Web3(cluster === "testnet" ? "https://api.testnet.abs.xyz" : "https://api.mainnet.abs.xyz");
const chainId = await web3.eth.getChainId();
console.log('Chain ID: ' + chalk.green(chainId));
prcsrContract = new web3.eth.Contract(PRCSR_ABI as ContractAbi, process.env.TESTNET_PRCSR_ADDRESS);
sender = web3.eth.accounts.wallet.add(process.env.DEPLOYER_PRIVATE_KEY as string)[0];
console.log('Sender: ' + chalk.green(sender.address));
console.log('Sender Balance: ' + chalk.green(web3.utils.fromWei(await web3.eth.getBalance(sender.address), 'ether')));
console.log('------------<Transaction Details>------------');
}
program
.version("1.0.0")
.description(`
Airdrop PRCSR tokens to a list of addresses
`)
program.command("airdrop")
.description("Airdrop PRCSR tokens to a list of addresses")
.option("-a, --address <address>", "Address to airdrop to")
.option("-n, --amount <amount>", "Amount of tokens to airdrop")
.option("-c, --cluster <cluster>", "Cluster to use", "testnet")
.action(async (options) => {
if (options.cluster !== "mainnet" && options.cluster !== "testnet") {
console.log(chalk.red("Invalid cluster"));
return;
}
await initSetup(options.cluster);
const mint_tx = await prcsrContract.methods.safeMint(options.address, options.amount).send({
from: sender.address,
})
console.log('mint tx events: ', mint_tx.events);
console.log('safeMint tx hash: ' + chalk.green(mint_tx.transactionHash));
console.log('------------<Transaction End>------------');
})
program.command("airdrop-all")
.description("Airdrop all PRCSR tokens to a list of addresses from a json file")
.option("-f, --file <file>", "Path to the json file containing the list of addresses")
.option("-c, --cluster <cluster>", "Cluster to use", "testnet")
.action(async (options) => {
if (options.cluster !== "mainnet" && options.cluster !== "testnet") {
console.log(chalk.red("Invalid cluster"));
return;
}
await initSetup(options.cluster);
const json_addresses = JSON.parse(fs.readFileSync(options.file, "utf8"));
const addresses: string[] = Object.keys(json_addresses);
const mint_array_tx = await prcsrContract.methods.safeMintArray(addresses).send({
from: sender.address,
})
console.log("mint array tx events: ", mint_array_tx.events);
console.log('Mint Array tx hash: ' + chalk.green(mint_array_tx.transactionHash));
console.log('------------<Transaction End>------------');
})
program.command("get balance")
.description("Get the balance of an address")
.option("-a, --address <address>", "Address to get the balance of")
.option("-c, --cluster <cluster>", "Cluster to use", "testnet")
.action(async (options) => {
if (options.cluster !== "mainnet" && options.cluster !== "testnet") {
console.log(chalk.red("Invalid cluster"));
return;
}
await initSetup(options.cluster);
const balance = await web3.eth.getBalance(options.address);
console.log('Balance: ' + chalk.green(web3.utils.fromWei(balance, 'ether')));
})
program.command("add-to-whitelist")
.description("Add an address to the whitelist")
.option("-f, --file <file>", "Path to the json file containing the list of addresses")
.option("-c, --cluster <cluster>", "Cluster to use", "testnet")
.action(async (options) => {
if (options.cluster !== "mainnet" && options.cluster !== "testnet") {
console.log(chalk.red("Invalid cluster"));
return;
}
await initSetup(options.cluster);
const json_addresses = JSON.parse(fs.readFileSync(options.file, "utf8"));
const addresses: string[] = Object.keys(json_addresses);
const amounts: number[] = Object.values(json_addresses);
const add_to_whitelist_tx = await prcsrContract.methods.addToWL(addresses, amounts).send({
from: sender.address,
})
console.log('add to whitelist tx events: ', add_to_whitelist_tx.events);
console.log('add to whitelist tx hash: ' + chalk.green(add_to_whitelist_tx.transactionHash));
console.log('------------<Transaction End>------------');
})
program.parse(process.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment