Move.

Post

Share your knowledge.

farshad.
Feb 13, 2025
Expert Q&A

Why does sponsored transaction fail with JsonRpcError?

I've been working on creating a sponsored transaction. I first create and sign the transaction with the gas sponsor and then the sender. But when I send it to the blockchain, I get a JsonRpcError: Deserialization error. Oddly enough, if I sign it without a sponsor, it works fine. Can anyone help me figure out what's going wrong with the sponsored transaction setup?

  • Move CLI
  • Move
2
2
Share
Comments
.

Answers

2
Xavier.eth.
Feb 13 2025, 11:09

It seems there may be an issue with the order or the process of signing the transaction. Make sure you're correctly building the transaction and then signing the serialized transaction. Here's a sample code that might help:

async function signSerializedTransaction({
  signer,
  serializedTransaction,
}: {
  signer: Keypair;
  serializedTransaction: string;
}) {
  const txBytes = fromB64(serializedTransaction);
  const signatureWithBytes = await signer.signTransaction(txBytes);

  return signatureWithBytes.signature;
}

async function run() {
  const client = new SuiClient({ url: FULLNODE_URL });
  const tx = ...;

  ...

  tx.setSender(USER_KEYPAIR.toSuiAddress());

  tx.setGasOwner(SPONS_KEYPAIR.toSuiAddress());

  const txBytes = await tx.build({ client });
  const txSerialized = toB64(txBytes);

  const userSignature = await signSerializedTransaction({
    signer: USER_KEYPAIR,
    serializedTransaction: txSerialized,
  });


  const sponsorSignature = await signSerializedTransaction({
    signer: SPONS_KEYPAIR,
    serializedTransaction: txSerialized,
  });

 
  const resp = await client.executeTransactionBlock({
    transactionBlock: txBytes,
    signature: [userSignature, sponsorSignature],
    options: {
      showObjectChanges: true,
      showEffects: true,
      showBalanceChanges: true,
    },
  });
  console.log(resp);
}
2
Best Answer
Comments
.
jogador_1.
Feb 13 2025, 11:08

Make sure that the signatures are properly handled and in the correct order when sending the transaction. The error message indicates that there might be a data formatting issue or a communication gap in how the transaction is serialized and signed.

1
Comments
.

Do you know the answer?

Please log in and share it.

Move is an executable bytecode language used to implement custom transactions and smart contracts.

148Posts231Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJune
We use cookies to ensure you get the best experience on our website.
More info