Move.

Bài viết

Chia sẻ kiến thức của bạn.

farshad.
Feb 13, 2025
Hỏi đáp Chuyên Gia

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
Chia sẻ
Bình luận
.

Câu trả lời

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

Có vẻ như có thể có một vấn đề với lệnh hoặc quá trình ký giao dịch. Đảm bảo bạn đang xây dựng chính xác giao dịch và sau đó ký giao dịch được nối tiếp. Đây là một mã mẫu có thể giúp:

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
Bình luận
.
jogador_1.
Feb 13 2025, 11:08

Đảm bảo rằng các chữ ký được xử lý đúng cách và theo đúng thứ tự khi gửi giao dịch. Thông báo lỗi cho biết rằng có thể có vấn đề về định dạng dữ liệu hoặc lỗ hổng giao tiếp trong cách giao dịch được nối tiếp và ký.

0
Bình luận
.

Bạn có biết câu trả lời không?

Hãy đăng nhập và chia sẻ nó.

Chúng tôi sử dụng cookie để đảm bảo bạn có trải nghiệm tốt nhất trên trang web của chúng tôi.
Thêm thông tin