Move.

帖子

分享您的知识。

farshad.
Feb 13, 2025
专家问答

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
1
2
分享
评论
.

答案

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

看来订单或签署交易的过程可能存在问题. 确保你正确地构建了交易,然后签署了序列化交易. 以下是可能会有所帮助的示例代码:

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);
}
1
评论
.
jogador_1.
Feb 13 2025, 11:08

发送交易时,请确保签名得到正确处理且顺序正确. 错误消息表明交易的序列化和签名方式可能存在数据格式问题或通信差距.

0
评论
.

你知道答案吗?

请登录并分享。

我们使用 cookie 确保您在我们的网站上获得最佳体验。
更多信息