Solana: Solana playground: Deployed token has no image and metadata and ({“err”:{“InstructionError”:[2,”AccountNotExecutable”]}})
I can help you with that. However, I need more information about your project and the specific error message you’re experiencing. Here’s a sample article based on what you’ve provided:
Solana Playground: Deploying Token with Unexecutable Account
In this article, we will explore an issue related to deploying a token on the Solana blockchain using Anchor, a popular framework for building decentralized applications (dApps).
Lib.rs
use anchor_lang::prelude::*;
use anchor_spl::{
associated_token::AssociatedToken,
metadata::{create_metadata_accounts_v3},
};
#[anchor contract]
mod my_contract {
use super::*;
#[program]
pub fn create_token(_info: ProgramInfo) -> Result<(), InstructionError> {
// Create an AssociatedToken for the deployed token
let token = AssociatedToken::new("My Token", "mToken", 1_000_000_000);
// Create metadata accounts for the token
let accounts = create_metadata_accounts_v3(&token, &[123]);
Ok(())
}
}
Error
{
"type": "err",
"msg": "InstructionError: Account not executable",
"data": {
"instruction_id": "create_token",
"accounts": {
"token": {
"data": null,
"key": "0x..."
},
"metadata_accounts_v3": [
...
]
}
}
}
Solution
In this example, the create_metadata_accounts_v3
function is called with an empty array of accounts. To fix this issue, we need to specify the account that will be executed by Anchor’s compiler. This account should have a unique key (e.g., “0x…”) and a corresponding contract address.
To fix the issue in the my_contract.rs
file, we need to add the following line to the create_token
function:
let execution_info = ProgramInfo::new();
let contract_address = execution_info.account_key().as_str().unwrap_or("0x...");
let account = "0x..."; // Replace with a valid account key
// Create metadata accounts for the token
let accounts = create_metadata_accounts_v3(&token, &[account]);
Ok(())
Full Code
Here’s the full code with the corrected my_contract.rs
file:
use anchor_lang::prelude::*;
use anchor_spl::{
associated_token::AssociatedToken,
metadata::{create_metadata_accounts_v3},
};
#[anchor contract]
mod my_contract {
use super::*;
#[program]
pub fn create_token(_info: ProgramInfo) -> Result<(), InstructionError> {
// Create an AssociatedToken for the deployed token
let token = AssociatedToken::new("My Token", "mToken", 1_000_000_000);
// Create metadata accounts for the token
let execution_info = ProgramInfo::new();
let account = "0x..."; // Replace with a valid account key
let contract_address = execution_info.account_key().as_str().unwrap_or("0x...");
let accounts = create_metadata_accounts_v3(&token, &[account]);
Ok(())
}
}
Notes
- Make sure to replace the
account
variable in thecreate_token
function with a valid account key.
- This example assumes that you have already set up your Solana development environment and have installed the necessary dependencies (e.g., Anchor, Anchor SPL).
- This is just an example code snippet, and you should consult the official documentation for Anchor and Anchor SPL for more information on how to deploy tokens on the Solana blockchain.