1

I'm really strugling to much on this one as I don't understand my error. My goal is to imput metadata on my token thx to Metaplex and here is my code :

   import {Collection, CreateMetadataAccountV3InstructionAccounts, 
   CreateMetadataAccountV3InstructionDataArgs, Creator, MPL_TOKEN_METADATA_PROGRAM_ID, 
    UpdateMetadataAccountV2InstructionAccounts, UpdateMetadataAccountV2InstructionData, 
    Uses, createMetadataAccountV3, updateMetadataAccountV2, findMetadataPda} from 
   "@metaplex-foundation/mpl-token-metadata"; import * as web3 from 
   "@solana/web3.js"; import { PublicKey, createSignerFromKeypair,
   isKeypairSigner, none, signerIdentity, some } from
   "@metaplex-foundation/umi"; import { createUmi } from
   '@metaplex-foundation/umi-bundle-defaults'; import {
   fromWeb3JsKeypair, fromWeb3JsPublicKey} from
   '@metaplex-foundation/umi-web3js-adapters';

   export function loadWalletKey(keypairFile:string): web3.Keypair {
   const fs = require("fs");
   const loaded = web3.Keypair.fromSecretKey(
     new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString())),
   );
   return loaded;   }

   const INITIALIZE = true;

   async function main(){
   const myKeypair = loadWalletKey("Nico9i5BasPEndBCFNiQ1RBQckzsDH1KWW6zXaXehZG.json")
   const mint = new web3.PublicKey("EgrbFEpsLX6eBZ25i11QPBQW3Dvum8yVEQetT5DwpHHx");

   const umi = createUmi("https://api.mainnet-beta.solana.com");
   const signer = createSignerFromKeypair(umi, fromWeb3JsKeypair(myKeypair))
   umi.use(signerIdentity(signer, true))

   const ourMetadata = { // TODO change those values!
       name: "SkullKingTrash", 
       symbol: "SSKT",
       uri: "https://raw.githubusercontent.com/TrashColaFR/uri/main/test.json",
   }
   const onChainData = {
       ...ourMetadata,
       // we don't need that
       sellerFeeBasisPoints: 0,
       creators: none<Creator[]>(),
       collection: none<Collection>(),
       uses: none<Uses>(),
   }
   if(INITIALIZE){
       const accounts: CreateMetadataAccountV3InstructionAccounts = {
           mint: fromWeb3JsPublicKey(mint),
           mintAuthority: signer,
       }
       const data: CreateMetadataAccountV3InstructionDataArgs = {
           isMutable: true,
           collectionDetails: null,
           data: onChainData
       }
       const txid = await createMetadataAccountV3(umi, {...accounts, ...data}).sendAndConfirm(umi);
       console.log(txid)
   } else {
       const data: UpdateMetadataAccountV2InstructionData = {
           data: some(onChainData),
           discriminator: 0,
           isMutable: some(true),
           newUpdateAuthority: none<PublicKey>(),
           primarySaleHappened: none<boolean>()
       }
       const accounts: UpdateMetadataAccountV2InstructionAccounts = {
           metadata: findMetadataPda(umi,{mint: fromWeb3JsPublicKey(mint)}),
           updateAuthority: signer
       }
       const txid = await updateMetadataAccountV2(umi, {...accounts, ...data} ).sendAndConfirm(umi);
       console.log(txid)
   }

   }

    main(); `

While the error is :

SendTransactionError: failed to send transaction: Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.
at Connection.sendEncodedTransaction (C:\Users\nicol\Documents\TokenSol2\node_modules@solana\web3.js\src\connection.ts:5921:13) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async Connection.sendRawTransaction (C:\Users\nicol\Documents\TokenSol2\node_modules@solana\web3.js\src\connection.ts:5880:20) at async Object.sendTransaction (C:\Users\nicol\Documents\TokenSol2\node_modules@metaplex-foundation\umi-rpc-web3js\src\createWeb3JsRpc.ts:327:25)

at async TransactionBuilder.sendAndConfirm (C:\Users\nicol\Documents\TokenSol2\node_modules@metaplex-foundation\umi\src\TransactionBuilder.ts:359:23) at async main (C:\Users\nicol\Documents\TokenSol2\mpl_metadata.ts:49:22) { logs: [] }

I’m a beginner, but I guess it’s not that hard. Someone more educated might be able to help me with this one

1 Answer 1

1

The wallet myKeypair is set as the signer for the umi instance. This means that it'll act as the payer and transaction fees will be debited from it.

The error likely means that this wallet hasn't been funded, and so has 0 SOL in it to pay for fees. There are a few ways to get devnet SOL, once of which is to run:

solana airdrop <amount> <your-wallet-address> --url d

To request a devnet airdrop to the specified wallet using the solana-cli. Note that this has rate-limits of about 2 SOL per hour, but that should be enough for what you need.

5
  • Well, first of all, thank you for your quick answer ! The problem is, I'm in the mainnet, and my sol account is of 0.24 already : '> solana airdrop 0.001 Nico9i5BasPEndBCFNiQ1RBQckzsDH1KWW6zXaXehZG --url d Requesting airdrop of 0.001 SOL Error: airdrop request failed. This can happen when the rate limit is reached. > solana balance Nico9i5BasPEndBCFNiQ1RBQckzsDH1KWW6zXaXehZG 0.24647912 SOL >'
    – TrashCola
    Feb 21 at 22:58
  • Your script tries to run on devnet: const umi = createUmi("https://api.devnet.solana.com");, and thus fails due to a lack of devnet sol. If you have mainnet sol then changing the rpc url to a mainnet url in the script should fix the error, as then your wallet would have an adequate balance You can only
    – Ademola
    Feb 22 at 0:56
  • I saw it thanks to your first message and sadly changing for : const umi = createUmi(new Connection("api.mainnet-beta.solana.com")); Or this const umi = createUmi("api.mainnet-beta.solana.com"); didn't help
    – TrashCola
    Feb 22 at 1:21
  • But once again, huge thanks for your help
    – TrashCola
    Feb 22 at 1:23
  • I've made an update of my @metaplex-foundation/mpl-token-metadata and it runs without any issue ! FINALLY ! 🥳🥳
    – TrashCola
    Feb 22 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.