import { mineGasForTransaction } from "@dirtroad/gasless";
import { createPublicClient, createWalletClient, http } from "viem";
import { skaleCalypsoTestnet } from "viem/chains";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
async function main() {
const privateKey = generatePrivateKey();
const client = createPublicClient({
chain: skaleCalypsoTestnet,
transport: http()
});
const wallet = createWalletClient({
chain: skaleCalypsoTestnet,
transport: http(),
account: privateKeyToAccount(privateKey)
});
// Generate gasless transaction parameters
const { gasPrice } = await mineGasForTransaction(100_000, wallet.account.address, 0);
// Send transaction with computed gas price
const transactionHash = await wallet.sendTransaction({
to: "0x62Fe932FF26e0087Ae383f6080bd2Ed481bA5A8A",
data: `0x0c11dedd000000000000000000000000${wallet.account.address.substring(2)}`,
gas: BigInt(100_000),
gasPrice: BigInt(gasPrice)
});
const receipt = await client.waitForTransactionReceipt({
hash: transactionHash
});
console.log("Gasless transaction receipt: ", receipt);
return receipt;
}
main().catch(console.error);