Skip to content

Instantly share code, notes, and snippets.

@zed-wong
Created December 6, 2023 03:25
Show Gist options
  • Save zed-wong/c28637ab9cabafdee8391d7e52534be9 to your computer and use it in GitHub Desktop.
Save zed-wong/c28637ab9cabafdee8391d7e52534be9 to your computer and use it in GitHub Desktop.
evm-inscription
// Change RPC and data for different network and different inscription
// Change privateKey to yours
// data is hex encoded string
// use [email protected]
import { ethers } from "ethers";
import { BigNumber } from "bignumber.js";
// Replace with your own private key
const privateKey = "";
// Connect to the Polygon network
const polygonRPC = "https://polygon-pokt.nodies.app"
const provider = new ethers.providers.JsonRpcProvider(polygonRPC);
// Create a wallet instance
const wallet = new ethers.Wallet(privateKey, provider);
async function a(nonce, boost) {
var maxFee;
var maxPriorityFee;
const gas = await fetch('https://gasstation.polygon.technology/v2')
.then(response => response.json())
.then(json => {
// console.log(json)
maxFee=ethers.utils.parseUnits(Number(json.fast.maxFee).toString(), "gwei")
maxPriorityFee=ethers.utils.parseUnits(Number(json.fast.maxPriorityFee).toString(), "gwei")
})
console.log('maxFee:',maxFee,'\nmaxPriorityFee:', maxPriorityFee)
if (boost) {
maxFee = maxFee.mul(ethers.BigNumber.from("2"))
maxPriorityFee = maxPriorityFee.mul(ethers.BigNumber.from("2"))
}
const toAddress = wallet.address;
// Data to include in the transaction (can be empty if not needed)
//const data = 'data:,{"p":"prc-20","op":"mint","tick":"poli","amt":"1000"}';
const data = '0x646174613a2c7b2270223a227072632d3230222c226f70223a226d696e74222c227469636b223a22706f6c69222c22616d74223a2231303030227d'
// Transaction object
const tx = {
type: 2,
to: toAddress,
data: data,
value: ethers.utils.parseEther("0"),
gasLimit: 40000,
maxFeePerGas: maxFee,
maxPriorityFeePerGas: maxPriorityFee,
// nonce: await wallet.getTransactionCount()
nonce: nonce,
chainId: 0x89,
};
// Sign the transaction
const signedTx = await wallet.signTransaction(tx);
// Send the transaction
const txResponse = await provider.sendTransaction(signedTx);
console.log("ob:", tx)
console.log("tx:", txResponse.hash);
}
async function getGas() {
var maxFee;
var maxPriorityFee;
const gas = await fetch('https://gasstation.polygon.technology/v2')
.then(response => response.json())
.then(json => {
console.log(json)
console.log(Number(json.standard.maxFee).toString())
console.log(Number(json.standard.maxPriorityFee).toString())
console.log(ethers.utils.parseUnits(Number(json.standard.maxFee).toString(), "gwei"))
console.log(ethers.utils.parseUnits(Number(json.standard.maxPriorityFee).toString(), "gwei"))
maxFee=ethers.utils.parseUnits(Number(json.standard.maxFee).toString(), "gwei")
maxPriorityFee=ethers.utils.parseUnits(Number(json.standard.maxPriorityFee).toString(), "gwei")
})
console.log('maxFee:',maxFee,'\nmaxPriorityFee:', maxPriorityFee)
return maxFee, maxPriorityFee
}
async function main(){
for (let i=1243; i<1500; i++) {
await a(i)
}
}
try{
main()
} catch(e){
console.log(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment