I'm trying to create a new SPL token using @solana/web3.js and @solana/spl-token at the end of the process I got this error Error occurred: Error: !signature. Even though I don't know if the weather code is correct or not.
export const getProvider = () => {
if (typeof window?.solana !== "undefined" && window?.solana?.isPhantom) {
return window.solana;
} else {
throw new Error("Phantom wallet is not available");
}
};
export const createToken = async () => {
try {
console.log("Initializing connection to Solana network...");
const connectionWallet = new web3.Connection("https://api.devnet.solana.com","confirmed");
console.log("Connection to Solana network established.");
console.log("Connecting to Phantom wallet...");
const account = await window.solana.connect();
const mintRequester = account?.publicKey;
console.log("Connected to Phantom wallet.");
// Connect to the wallet
console.log("Fetching provider...");
const provider = await getProvider();
console.log("Provider fetched successfully.");
// Get the payer's public key from the wallet
const payerPublicKey = mintRequester;
// Generate a new mint account
console.log("Generating new mint account...");
const mint = await web3.Keypair.generate();
console.log("New mint account generated:", mint.publicKey.toString());
// Construct the token create transaction
console.log("Constructing token create transaction...");
const instructions = [
await splToken.createInitializeMintInstruction(
mint.publicKey,
0,
payerPublicKey,
null,
splToken.TOKEN_PROGRAM_ID
),
];
// Sign the transaction
console.log("Signing the transaction...");
const transaction = await new web3.Transaction().add(...instructions);
const latestBlockhash = await connectionWallet.getLatestBlockhash();
transaction.feePayer = payerPublicKey;
transaction.recentBlockhash = latestBlockhash.blockhash;
console.log("🚀 ~ createToken ~ connectionWallet:", connectionWallet)
console.log("🚀 ~ createToken ~ connectionWallet:", provider.signTransaction.toString())
const signedTransaction = await provider.signTransaction(transaction, [
mint,
]);
console.log("Transaction signed successfully:", signedTransaction);
// Send the transaction to the network
console.log("Sending the transaction to the network...");
const signature = await connectionWallet.sendTransaction(
signedTransaction,
[mint]
);
console.log("Transaction sent successfully. Signature:", signature);
// Return the new mint public key
console.log("New mint public key:", mint.publicKey.toString());
return mint.publicKey;
} catch (error) {
console.error("Error occurred:", error);
}
};