helius-labs / helius-sdk

123 stars 39 forks source link

fix(txts): Address Issue When Using Different Fee Payer Account #100

Closed 0xIchigo closed 2 months ago

0xIchigo commented 2 months ago

This PR addresses the issue outlined in #96 where the transaction fails during signature verification when using a different feePayer account. I have implemented their second proposed solution

tavindev commented 2 months ago

Hey @0xIchigo, I'm getting this error when testing the method.

Code sample:

 const wallet = Keypair.fromSecretKey(
// ...
  );
  const to = new PublicKey(
// ...
);

  await helius.rpc.sendSmartTransaction(
    [
      createTransferInstruction(
        wallet.publicKey,
        to,
        wallet.publicKey,
        0.001 * LAMPORTS_PER_SOL,
      ),
    ],
    [wallet],
  );

Error:

Simulation error: {
  "InstructionError": [
    2,
    "InvalidAccountData"
  ]
}
Error: Error sending smart transaction: Error: Error fetching compute units for the instructions provided
    at RpcClient.<anonymous> (/Users/tavin/repos/test/node_modules/.pnpm/github.com+helius-labs+helius-sdk@f4bbdb7515fab36d40211939d787b25bfb1063e5_arweave@1.15.0_fas_7tljtjpvvt43lwoxhu2flws4gu/node_modules/helius-sdk/dist/src/RpcClient.js:572:23)
    at Generator.throw (<anonymous>)
    at rejected (/Users/tavin/repos/test/node_modules/.pnpm/github.com+helius-labs+helius-sdk@f4bbdb7515fab36d40211939d787b25bfb1063e5_arweave@1.15.0_fas_7tljtjpvvt43lwoxhu2flws4gu/node_modules/helius-sdk/dist/src/RpcClient.js:6:65)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
0xIchigo commented 2 months ago

@tavindev have you tried creating the instruction first before passing it into sendSmartTransaction? I'm able to send both legacy and versioned transactions with the following snippet:

const fromPubkey = keypair.publicKey;
const toPubkey = new PublicKey("");

let balanceFrom = await helius.connection.getBalance(fromPubkey);
let balanceTo = await helius.connection.getBalance(toPubkey);

// Create transaction instructions
const instructions: TransactionInstruction[] = [
    SystemProgram.transfer({
        fromPubkey: fromPubkey,
        toPubkey: toPubkey,
        lamports: 0.001 * LAMPORTS_PER_SOL, // Send 0.001 SOL
    }),
];

let address_lut: AddressLookupTableAccount[] = [];

try {
    // Call the sendSmartTransaction function
    const txSig = await helius.rpc.sendSmartTransaction(instructions, [keypair], address_lut);
    console.log(`Transaction sent successfully with signature: ${txSig}`);

    // Check balances after transfer
    balanceFrom = await helius.connection.getBalance(fromPubkey);
    console.log("From Wallet Balance:", balanceFrom / LAMPORTS_PER_SOL, "SOL");

    balanceTo = await helius.connection.getBalance(toPubkey);
    console.log("To Wallet Balance:", balanceTo / LAMPORTS_PER_SOL, "SOL");
  } catch (error: any) {
    console.error(`Failed to send transaction: ${error.message}`);
  }
tavindev commented 2 months ago

Working now. I just realized I was using createTransferInstruction from "@solana/spl-token" package, hence why it wasn't working. Thanks!