Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add init field to account IDL #15

Open
armaniferrante opened this issue Jan 10, 2021 · 1 comment
Open

Add init field to account IDL #15

armaniferrante opened this issue Jan 10, 2021 · 1 comment

Comments

@armaniferrante
Copy link
Member

armaniferrante commented Jan 10, 2021

Filing a tracking issue, though I don't love the idea at the moment and am inclined to throw this idea away.

IDL change and client generation

An additional feature the #[account(init)] attribute enables is the ability for clients to know when they should create accounts in the same transaction as executing a program instruction.

Currently, when executing this type of instruction, clients must manually add the account creation instruction as follows.

// The Account to create.
const myAccount = new anchor.web3.Account();

// Atomically create the new account and initialize it with the program.
await program.rpc.myInstruction(...args, {
  accounts: {
    myAccount: myAccount.publicKey,
  },
  signers: [myAccount],
  instructions: [
    await program.account.MyAccount.createInstruction(myAccount),
  ],
});

With the #[anchor(init)] attribute, this example can be transformed into

await program.rpc.myInstruction(...args);

Since the client generator can read a new isInit field in the IDL

// idl.json
{
...,
instructions: {
  ...,
  {
    "name:" "myInstruction",
    "accounts": [...],
    "isInit": true,
    "isMut": true,
    "isSigner": true,
     ...
   }
}
@anoushk1234
Copy link
Contributor

@armaniferrante should i take this up? I was building a transpiler for anchor to seahorse and this was a problem as it doesnt know which accounts are being initialized

vadorovsky added a commit to vadorovsky/anchor that referenced this issue May 18, 2023
vadorovsky added a commit to vadorovsky/anchor that referenced this issue Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants