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

createAccountsMintsAndTokenAccounts method doesn't work #62

Open
serjou1 opened this issue Nov 2, 2024 · 1 comment
Open

createAccountsMintsAndTokenAccounts method doesn't work #62

serjou1 opened this issue Nov 2, 2024 · 1 comment

Comments

@serjou1
Copy link

serjou1 commented Nov 2, 2024

Here is my code:

const provider = anchor.AnchorProvider.env();
  anchor.setProvider(provider);

  const user = (provider.wallet as anchor.Wallet).payer;
  const payer = user;

  console.log("Payer: ", payer.publicKey.toBase58());

  const connection = provider.connection;

  const accounts = {
    tokenProgram: TOKEN_PROGRAM,
    usdtMint: Keypair.generate().publicKey,
  };

  let owner: anchor.web3.Keypair;
  let regularUser: anchor.web3.Keypair;
  let usdtMint: anchor.web3.Keypair;

  [owner, regularUser, usdtMint] = makeKeypairs(3);

  beforeAll(
    async () => {
      const userMintsAndTokenAccounts =
        await createAccountsMintsAndTokenAccounts(
          [
            [0],
            [1_000_000_000]
          ],
          1 * LAMPORTS_PER_SOL,
          connection,
          payer
        );

      const { users, mints } = userMintsAndTokenAccounts;

      owner = users[0];
      regularUser = users[1];

      usdtMint = mints[0];

      accounts.usdtMint = usdtMint.publicKey;
    }
  );
  

Here is my log:

console.log
  Payer:  zYQ4w3n2evWNHZir1CuYyxR7Kraw7Ec78JverL4Nu55

And I'm getting this error:

Cannot sign with non signer key FrxYm1E1KYUZHxKWXVnDeu6V1GUTJfo3riAtL1Aj3EFy

      at assert (node_modules/@solana/web3.js/src/utils/assert.ts:6:11)
      at VersionedTransaction.assert [as sign] (node_modules/@solana/web3.js/src/transaction/versioned.ts:104:7)
      at makeAndSendAndConfirmTransaction (node_modules/@solana-developers/helpers/src/lib/token.ts:262:15)
      at createAccountsMintsAndTokenAccounts (node_modules/@solana-developers/helpers/src/lib/token.ts:93:3)

My env:

serjou@Sergejs-MacBook-Pro anchor % anchor --version
anchor-cli 0.30.1
serjou@Sergejs-MacBook-Pro anchor % solana --version
solana-cli 2.0.15 (src:7feb24da; feat:4052914393, client:Agave)
@serjou1
Copy link
Author

serjou1 commented Nov 2, 2024

The method only works with 2 mints and 2 users, moreover, no one of users can have 0 both token balances.

I had to change code to:

const userMintsAndTokenAccounts =
        await createAccountsMintsAndTokenAccounts(
          [
            [0, 1],
            [1_000_000_000, 0]
          ],
          1 * LAMPORTS_PER_SOL,
          connection,
          payer
        );

This should be documented or method should be rewritten

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

1 participant