Error: AccountNotFound with Anchor Deploy on Solana
As a Solana developer, you may encounter an error when trying to deploy your program using the Anchor SDK. A common error is “AccountNotFound,” which occurs when the Anchor node is unable to find the account associated with the specified program contract address.
In this article, we will walk you through the steps to troubleshoot and resolve the AccountNotFound error with Anchor deployed on Solana.
What is an AccountNotFound error?
An AccountNotFound error indicates that the Anchor node cannot find the account associated with the specified program contract address. This can happen for several reasons:
- The contract address does not exist on the Anchor node.
- The contract address is not configured or deployed correctly on the Solana blockchain.
- The
id.json
file, which contains information about the program and its deployment, is incomplete or corrupt.
Troubleshooting Steps
To resolve the AccountNotFound error with your Anchor implementation on Solana, follow these steps:
1. Check the contract address
First, make sure that the contract address specified in your code matches the one stored in the id.json
file. You can check the contractAddress
value in your code:
const id = anchor.import("path/to/id.json");
const contractAddress = id.address();
2. Check the Anchor node configuration
Verify that the Anchor node is configured correctly to find the account associated with the specified program’s contract address. You can check the id.json
file for any errors or inconsistencies:
{
"id": {
"contractAddress": "0x...",
"programId": "path/to/program.id"
}
}
3. Inspect the Solana blockchain status
Use the Solana CLI “solana inspect” command to check if the contract address exists on the blockchain:
solana inspect --json
This will display information about the account, including its balance and transactions.
4. Verify the program deployment
Double-check that your program is deployed correctly using the Anchor SDK:
const { deploy } = require("@anchorlib/solana");
// Configure the Anchor node instance
const anchor = require("@anchorlib/solana");
const programId = "path/to/program.id";
try {
// Deploy the contract
await deploy(programId, {
accounts: [
{
key: programId,
KeyIndex: 0,
account: null,
arguments: []
}
]
});
} catch (error) {
console.error(error);
}
5. Update the id.jsonfile
If you suspect that theid.jsonfile is incomplete or corrupt, try updating it with a new version:
{
"contractAddress": "0x...",
"programId": "path/to/program.id"
}
After resolving the AccountNotFound error, make sure that your program is deployed and configured properly on the Solana blockchain.
Conclusion
In this article, we have gone through the steps to troubleshoot and resolve the AccountNotFound error with Anchor deployment on Solana. By verifying the contract address, verifying the Anchor node configuration, inspecting the Solana blockchain status, and updating the id.json` file as needed, you should be able to resolve this issue and successfully deploy your program using the Anchor SDK.