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

unable to create multisig using cpi in this example #4

Open
pruales opened this issue Jul 10, 2024 · 2 comments
Open

unable to create multisig using cpi in this example #4

pruales opened this issue Jul 10, 2024 · 2 comments

Comments

@pruales
Copy link

pruales commented Jul 10, 2024

I get this error:
AnchorError caused by account: multisig. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized.

import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { TsumoriCredibleAccountPoc } from "../target/types/tsumori_credible_account_poc";
import { generateFundedKeypair } from "./util";

const SQUADS_PROGRAM_ID = new anchor.web3.PublicKey(
  "SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf"
);
function toUtfBytes(str: string): Uint8Array {
  return new TextEncoder().encode(str);
}
const SEED_PREFIX = toUtfBytes("multisig");
const SEED_MULTISIG = toUtfBytes("multisig");
const SEED_PROGRAM_CONFIG = toUtfBytes("program_config");

const getProgramConfigPda = () => {
  return anchor.web3.PublicKey.findProgramAddressSync(
    [SEED_PREFIX, SEED_PROGRAM_CONFIG],
    SQUADS_PROGRAM_ID
  );
};

const getMultisigPDA = (createKey: anchor.web3.PublicKey) => {
  return anchor.web3.PublicKey.findProgramAddressSync(
    [SEED_PREFIX, SEED_MULTISIG, createKey.toBytes()],
    SQUADS_PROGRAM_ID
  );
};

describe("tsumori-credible-account-poc", () => {
  const createKey = anchor.web3.Keypair.generate();
  const [multisigPda] = getMultisigPDA(createKey.publicKey);
  const [programConfig] = getProgramConfigPda();

  anchor.setProvider(anchor.AnchorProvider.env());

  const program = anchor.workspace
    .TsumoriCredibleAccountPoc as Program<TsumoriCredibleAccountPoc>;

  it("create multisig", async () => {
    const creator = await generateFundedKeypair(
      anchor.getProvider().connection
    );

    const wallet = new anchor.Wallet(creator);
    const tx = await program.methods
      .createMultisig()
      .accounts({
        signer: creator.publicKey,
        createKey: createKey.publicKey,
        multisig: multisigPda,
        systemProgram: anchor.web3.SystemProgram.programId,
        programConfig,
        sqaudsProgramTreasury: anchor.web3.SystemProgram.programId,
        squadsMultisigProgram: SQUADS_PROGRAM_ID,
      })
      .signers([wallet.payer, createKey])
      .rpc();
    console.log("Your transaction signature", tx);
  });
});
@joeymeere
Copy link
Contributor

Can you provide a minimal example in the context of this repo? It's a bit difficult to debug this with the edits that have been made + custom program added.

@pruales
Copy link
Author

pruales commented Jul 11, 2024

Can you provide a minimal example in the context of this repo? It's a bit difficult to debug this with the edits that have been made + custom program added.

hey yeah its just a copy of the create multisig example in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants