I was following this guide to learn anchor: https://www.quicknode.com/guides/solana-development/anchor/transfer-tokens
When deploying the program via Solana Playground (as instructed), everything runs fine. The issue comes from trying to replicate on my local machine using anchor. The code is exactly the same; however I was running into this issue when trying to invoke the transferLamports
function:
'Program log: Instruction: TransferLamports',
'Program log: AnchorError caused by account: to. Error Code: ConstraintMut. Error Number: 2000. Error Message: A mut constraint was violated.',
After much, much frustration I discovered that the issue is with the IDL that Anchor generates when building the program. Comparing to the one that Solana Playground generates (remember - exact same lib.rs
):
Solana Playground
"accounts":[
{"name":"from","isMut":true,"isSigner":true},
{"name":"to","isMut":true,"isSigner":false},
{"name":"systemProgram","isMut":false,"isSigner":false}],
"args":[{"name":"amount","type":"u64"}]}]
Local Anchor
"accounts": [
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "recipient",
"writable": true
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": [
{
"name": "amount",
"type": "u64"
}
]
Pulling down the IDL from Solana Playground and using that in my Typescript module instead allows the code to run just fine.
const sig = program.methods.transferLamports(new BN(10000)).accounts({
from: from.publicKey,
to: to.publicKey,
system_program: system_program
})
What is causing anchor to produce a completely different IDL type that isn't compatible with anchor itself?