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

The returned transaction signature is wrong (Reached end of buffer unexpectedly) #805

Open
jiahuamld opened this issue Feb 25, 2025 · 0 comments

Comments

@jiahuamld
Copy link

I used the code generated by Solana's xfer.
const automaticBridge = await fromChain.getAutomaticTokenBridge();
xfer = automaticBridge.transfer
web3.Transaction.from(transactionBuffer) or web3.VersionedTransaction.deserialize

The returned transaction signature is wrong (Reached end of buffer unexpectedly)

{
"transaction": {
"recentBlockhash": null,
"feePayer": "HLZFstYdaZYAYdP1nsbPseSd4AouL1g2fFvNwmSSC7YA",
"nonceInfo": null,
"instructions": [
{
"keys": [
{
"pubkey": "HLZFstYdaZYAYdP1nsbPseSd4AouL1g2fFvNwmSSC7YA",
"isSigner": true,
"isWritable": true
},
{
"pubkey": "BYfFFqRS3Vdi7jJjomjLEzPeuNbHXkAYLeTzBiQtXdi5",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "7SAdSwDR7AJyzejaH3NF3Pv5ghq8pycFkpsn6e4kh71n",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "6FFgAjr3dwzFjEo3E7ZmfwGmngToSm9zDu1Le3vnFGQs",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "A9mUU4qviSctJVPJdBJWkb28deg915LYJKrzQ19ji3FM",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "GjiamzTxjnHGE69ssKQ9Cdz7DRVrAeDajGema7z77YTB",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "3ruHj8LUxcdWVunrwQ7EquBFs9215LoFafKEY2xzmULy",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "AYBTAcgbCoLGeyizPoayf3hj9CmE6Vz9dy6yBm5hsxzq",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "7YL41XffEmWCr9nBNRR3cRbE56ekr7UNm8bbh1z67k7E",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "DapiQYH3BGonhN8cngWcXQ6SrqSm3cwysoznoHr6Sbsx",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "7oPa2PHQdZmjSPqvpZN7MQxnC7Dcf3uL4oLqknGLk2S3",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "2yVjuQwpsvdsrywzsJJVs9Ueh4zayyo5DYJbBNc3DDpn",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "CBcBcetwAgZrkp2Gd27SNkmhHNCqpaPywnpaDmkuJj17",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "Gv1KWf8DT1jKv5pKBmGaTmVszqa56Xn8YGx2Pg7i7qAk",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "GF2ghkjwsR9CHkGk1RvuZrApPZGBZynxMm817VNi51Nf",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "9bFNrXNb2WTx8fMHXCheaZqkLZ3YCCaiqTftHxeintHy",
"isSigner": false,
"isWritable": true
},
{
"pubkey": "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "11111111111111111111111111111111",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "SysvarC1ock11111111111111111111111111111111",
"isSigner": false,
"isWritable": false
},
{
"pubkey": "SysvarRent111111111111111111111111111111111",
"isSigner": false,
"isWritable": false
}
],
"programId": "3vxKRPwUTiEkeUVyoZ9MXFe1V71sRLbLqu1gRYaWmehQ",
"data": [
25,
63,
69,
217,
250,
9,
127,
122,
0,
45,
49,
1,
0,
0,
0,
0,
198,
11,
0,
0,
0,
0,
0,
0,
4,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
189,
223,
2,
119,
42,
95,
127,
117,
190,
45,
180,
233,
189,
24,
15,
89,
248,
235,
222,
145,
0,
0,
0,
0
]
}
],
"signers": []
}
}

My code

import { wormhole } from "@wormhole-foundation/sdk";
import { toNative, TokenAddress } from "@wormhole-foundation/sdk-definitions";
import { Wormhole } from "@wormhole-foundation/sdk-connect";
import { amount } from "@wormhole-foundation/sdk";
import evm from "@wormhole-foundation/sdk/evm";
import solana from "@wormhole-foundation/sdk/solana";
import sui from "@wormhole-foundation/sdk/sui";
import { TokenTransfer } from "@wormhole-foundation/sdk-connect";
import { Transaction } from "@solana/web3.js";
import { VersionedTransaction } from "@solana/web3.js";

async function testTransfer() {
try {
const wh = await wormhole("Mainnet", [evm, solana, sui], {
chains: {
Solana: {
rpc: "https://api.mainnet-beta.solana.com",
},
Bsc: {
rpc: "https://bsc-dataseed1.binance.org",
},
Sui: {
rpc: "https://sui-mainnet.blockvision.org/",
}
}
});

const params = {
  from: {
    chain: "Solana" as const,
    address: "HLZFstYdaZYAYdP1nsbPseSd4AouL1g2fFvNwmSSC7YA"
  },
  to: {
    chain: "Bsc" as const,
    address: "0xbddf02772a5f7f75be2db4e9bd180f59f8ebde91"
  },
  token: {
    chain: "Solana" as const,
    address: "A9mUU4qviSctJVPJdBJWkb28deg915LYJKrzQ19ji3FM"
  },
  amount: "20"
};

const fromChain = await wh.getChain(params.from.chain);
const automaticBridge = await fromChain.getAutomaticTokenBridge();

const senderAddress = toNative(params.from.chain, params.from.address);
const recipient = Wormhole.chainAddress(params.to.chain, params.to.address);
const tokenAddress = toNative(params.token.chain, params.token.address) as TokenAddress<"Solana">;
const transferAmount = amount.units(amount.parse(params.amount, 6));

const tokenAccount = await fromChain.getTokenAccount(senderAddress, tokenAddress);

if (!tokenAccount) {
  return;
}

const destChain = await wh.getChain(params.to.chain);
const destTokenAddress = await TokenTransfer.lookupDestinationToken(
  fromChain,
  destChain,
  {
    chain: params.from.chain,
    address: tokenAddress
  }
);

const dtb = await destChain.getAutomaticTokenBridge();
const maxNativeAmountIn = await dtb.maxSwapAmount(destTokenAddress.address);
const nativeGas = maxNativeAmountIn / 10000n;
const actualNativeGas = await dtb.nativeTokenAmount(destTokenAddress.address, nativeGas);

const quote = await TokenTransfer.quoteTransfer(
  wh,
  fromChain,
  destChain,
  {
    token: {
      chain: params.from.chain,
      address: tokenAddress
    },
    amount: transferAmount,
    automatic: true,
    nativeGas: nativeGas
  }
);

if (quote.destinationToken.amount < 0n) {
  return;
}

const xfer = automaticBridge.transfer(
  senderAddress,
  recipient,
  tokenAddress,
  transferAmount,
  nativeGas
);

const transactions = [];
for await (const tx of xfer) {
  const rawTx = tx.transaction;
  const isVersionedTransaction = rawTx.instructions && rawTx.version !== undefined;
  transactions.push({
    type: isVersionedTransaction ? "versioned" : "legacy",
    base64: Buffer.from(JSON.stringify(rawTx)).toString('base64')
  });
}

return { transactions };

} catch (error) {
throw error;
}
}

testTransfer().then(result => {
console.log(JSON.stringify(result, null, 2));
}).catch(error => {
console.error("Error:", error.message);
});

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