solana-developers / helpers

JS/TS helpers for Solana
https://www.npmjs.com/package/@solana-developers/helpers
82 stars 25 forks source link

createAccountsMintsAndTokenAccounts method doesn't work #62

Open serjou1 opened 3 weeks ago

serjou1 commented 3 weeks ago

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 commented 3 weeks ago

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