Reputation: 411
Getting the following error every time script is run:
TransactionExpiredBlockheightExceededError: Signature [SIGNATURE] has expired: block height exceeded.
Script:
import { percentAmount, generateSigner, signerIdentity, createSignerFromKeypair } from '@metaplex-foundation/umi';
import { TokenStandard, createAndMint } from '@metaplex-foundation/mpl-token-metadata';
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { mplCandyMachine } from "@metaplex-foundation/mpl-candy-machine";
import "@solana/web3.js";
import secret from './guideSecret.json';
const umi = createUmi('[QuickNode Endpoint URL]'); //Replace with your QuickNode RPC Endpoint
const userWallet = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secret));
const userWalletSigner = createSignerFromKeypair(umi, userWallet);
const metadata = {
name: "Token Name",
symbol: "TOKEN",
uri: "[URI]",
};
const mint = generateSigner(umi);
umi.use(signerIdentity(userWalletSigner));
umi.use(mplCandyMachine());
void async function() {
try {
await createAndMint(umi, {
mint,
authority: umi.identity,
name: metadata.name,
symbol: metadata.symbol,
uri: metadata.uri,
sellerFeeBasisPoints: percentAmount(0),
decimals: 8,
amount: 1000000,
tokenOwner: userWallet.publicKey,
tokenStandard: TokenStandard.Fungible,
}).sendAndConfirm(umi);
console.log("Successfully minted 1 million tokens (", mint.publicKey, ")");
} catch (error) {
console.error(error);
}
}();
Unfortunately, the error is not verbose and I am stumped as to what is missing/incorrect. As far as I can tell, this is using the latest Solana libraries to create and mint the tokens.
Upvotes: 2
Views: 1271
Reputation: 401
Try using latest blockhash and add priority fee
import { percentAmount, generateSigner, signerIdentity, createSignerFromKeypair } from '@metaplex-foundation/umi';
import { setComputeUnitLimit, setComputeUnitPrice} from '@metaplex-foundation/mpl-toolbox'
import { TokenStandard, createAndMint } from '@metaplex-foundation/mpl-token-metadata';
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { mplCandyMachine } from "@metaplex-foundation/mpl-candy-machine";
import "@solana/web3.js";
import secret from './guideSecret.json';
const umi = createUmi('[QuickNode Endpoint URL]'); //Replace with your QuickNode RPC Endpoint
const userWallet = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secret));
const userWalletSigner = createSignerFromKeypair(umi, userWallet);
const metadata = {
name: "Token Name",
symbol: "TOKEN",
uri: "[URI]",
};
const mint = generateSigner(umi);
umi.use(signerIdentity(userWalletSigner));
umi.use(mplCandyMachine());
void async function() {
try {
const builder = new TransactionBuilder();
await builder.setLatestBlockhash(umi, { commitment: 'finalized' })
builder.add(
createAndMint(umi, {
mint,
authority: umi.identity,
name: metadata.name,
symbol: metadata.symbol,
uri: metadata.uri,
sellerFeeBasisPoints: percentAmount(0),
decimals: 8,
amount: 1000000,
tokenOwner: userWallet.publicKey,
tokenStandard: TokenStandard.Fungible,
}).items
)
builder.add(setComputeUnitLimit(umi, { units: 600_000 }))
builder.add(setComputeUnitPrice(umi, { microLamports: 20220000 }));
await builder.sendAndConfirm(umi, {
send: {
skipPreflight: false
},
confirm: {
commitment: "finalized",
}
});
console.log("Successfully minted 1 million tokens (", mint.publicKey, ")");
} catch (error) {
console.error(error);
}
}();
Upvotes: 2
Reputation: 33
You need to sign the transaction before sending it. Try out following code:
const createAndMintBuild = createAndMint(umi, {
mint,
authority: umi.identity,
name: metadata.name,
symbol: metadata.symbol,
uri: metadata.uri,
sellerFeeBasisPoints: percentAmount(0),
decimals: 8,
amount: 1000000000_00000000,
tokenOwner: userWallet.publicKey,
tokenStandard: TokenStandard.Fungible,
});
let builder = transactionBuilder()
.add(createAndMintBuild)
;
builder.setFeePayer(userWalletSigner);
builder.buildAndSign(umi);
const confirmResult = await builder.sendAndConfirm(umi).then(() => {
console.log("Successfully minted 1 billion tokens (", mint.publicKey, ")"); });
}
Upvotes: 1