So i've written a small program and it builds and deploys correctly. Initialize function also works.
But now I'm trying to create a Lottery and ts keeps repeting type error or something like that, the error message is:
/home/memewhales/solana_youtube_lottery/lottery-sol/node_modules/ts-node/src/index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^ TSError: ⨯ Unable to compile TypeScript: client/init2.ts:79:13 - error TS2345: Argument of type '{ lottery:
PublicKey; master: PublicKey; authority: PublicKey; systemProgram:
PublicKey; }' is not assignable to parameter of type
'ResolvedAccounts<{ name: "lottery"; writable: true; pda: { seeds: [{
kind: "const"; value: [108, 111, 116, 116, 101, 114, 121]; }, { kind:
"account"; path: "master.last_id"; account: "master"; }]; }; } | {
name: "master"; writable: true; pda: { ...; }; } | { ...; } | { ...;
}>'. Object literal may only specify known properties, and 'lottery'
does not exist in type 'ResolvedAccounts<{ name: "lottery"; writable:
true; pda: { seeds: [{ kind: "const"; value: [108, 111, 116, 116, 101,
114, 121]; }, { kind: "account"; path: "master.last_id"; account:
"master"; }]; }; } | { name: "master"; writable: true; pda: { ...; };
} | { ...; } | { ...; }>'.
79 lottery: lotteryPda,
~~~~~~~~~~~~~~~~~~~
Here's my function call on ts:
const ticketPrice = new anchor.BN(1);
// await program.methods.createLottery([]).accounts({
// authority: masterPda
// }).signers([payer]).rpc();
await program.methods
// Call the set_favorites instruction handler
.createLottery(ticketPrice)
.accounts({
lottery: lotteryPda,
master: masterPda,
authority: payer.publicKey,
systemProgram: programId
})
// Sign the transaction
.signers([payer])
.rpc()
// Send the transa
console.log('Lottery created with PDA: ', lotteryPda.toBase58());
Here's the type 'lottery_sol.ts':
"instructions": [
{
"name": "createLottery",
"discriminator": [
242,
165,
247,
119,
17,
203,
21,
42
],
"accounts": [
{
"name": "lottery",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
108,
111,
116,
116,
101,
114,
121
]
},
{
"kind": "account",
"path": "master.last_id",
"account": "master"
}
]
}
},
{
"name": "master",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
109,
97,
115,
116,
101,
114
]
}
]
}
},
{
"name": "authority",
"writable": true,
"signer": true
},
{
"name": "systemProgram",
"address": "11111111111111111111111111111111"
}
],
"args": [
{
"name": "ticketPrice",
"type": "u64"
}
]
},
The names match up however I don't get this ' PublicKey; }' is not assignable to parameter of type 'ResolvedAccounts<{ name: "lottery"'
Thanks