Copy import {Environment, MigrationDex, MintTokenCurveType, Moonshot} from "@wen-moon-ser/moonshot-sdk-evm";
import {JsonRpcProvider, Transaction, Wallet} from "ethers";
const mintTx = async () => {
const provider = new JsonRpcProvider(process.env.RPC_URL as string);
const signer = new Wallet('private_key', provider);
const moonshot = new Moonshot({
signer,
env: Environment.TESTNET,
});
const mockImg = '...';
const prepMint = await moonshot.prepareMintTx({
name: 'TEST_TOKEN',
symbol: 'TEST_TOKEN',
curveType: MintTokenCurveType.CONSTANT_PRODUCT_V1,
migrationDex: MigrationDex.UNISWAP, // USE MigrationDex.ABSTRACTSWAP for abstract
icon: mockImg,
description: 'TEST_TOKEN',
links: [{ url: 'https://x.com', label: 'x handle' }],
banner: mockImg,
creator: await signer.getAddress(),
tokenAmount: '10000000000000',
});
const deserializedTransaction = Transaction.from(
prepMint.transaction,
).toJSON();
const walletAddress = await signer.getAddress();
const feeData = await provider.getFeeData();
const tx = {
...deserializedTransaction,
gasPrice: feeData.gasPrice,
from: walletAddress,
nonce: await provider.getTransactionCount(walletAddress, 'latest'),
};
const gasLimit = await provider.estimateGas(tx);
const txResponse = await signer.sendTransaction({
...tx,
gasLimit,
});
const receipt = await txResponse.wait();
if (receipt?.status === 1) {
const res = await moonshot.submitMintTx({
token: prepMint.token,
signedTransaction: JSON.stringify(txResponse),
tokenId: prepMint.draftTokenId,
});
const createdTokenAddress = receipt?.logs[0].address;
console.log(createdTokenAddress);
}
}