0

I have two functions. The first function: Generates payload of unsigned_transaction: The second function: Needs to generate a signed transaction, using unsigned_transaction and signature.

Process: First one generates unsigned_tx hex using the data its provided and then caller of function signs the payload generated by first functions and call the second function to generate signed transaction.

What i looked into: subxt create_signed_with_nonce takes the signer to generate a signature but I already have a generated signature which i want to use so can't use it. Any suggested solution for this problem?

2 Answers 2

2

Subxt should be able to do anything that makes sense in this area.

For your first function, Subxt can help to construct the "call data" part of an extrinsic (check out the examples in general to see how we can build a transaction, eg here: https://github.com/paritytech/subxt/blob/33a9ec91afd16c459871e24ae18576f7afbb87c1/examples/examples/balance_transfer.rs#L34, and then with that you can call api.tx().call_data(the_tx) to get the call data bytes from it).

For your second function, I'm not exactly clear what the "signature" is that you're referring to (ie is it in fact a combination of signature and extra params?). To step back, a signed extrinsic consists roughly of the following, in order (SCALE encoded):

  • compact encoded length in bytes of the extrinsic
  • 1 byte: 0b10000000 + 4u8 (for "this is signed" + "version 4 format")
  • Address that extrinsic is sent from
  • Signature (not only the call data but additional and extra params are also signed)
  • The call data.

So depending on what you actually have already, it should be fairly straightforward to piece the parts together. The subxt source on building an extrinsic is, IMO, very readable too, and might help:

https://github.com/paritytech/subxt/blob/33a9ec91afd16c459871e24ae18576f7afbb87c1/subxt/src/tx/tx_client.rs#L124

And finally, just to say that the "standard" approach here would be that you would construct and sign an extrinsic all via Subxt (by providing any Signer implementation to do the actual signing), optionally entirely offline, and then use Subxt to then submit those bytes from a network enabled device.

1

Take a look at TxWrapper, it has exactly this function. https://github.com/paritytech/txwrapper-core/blob/v4.0.1/packages/txwrapper-core/src/core/construct/createSignedTx.ts

function createSignedTx(
    unsigned: UnsignedTransaction,
    signature: `0x${string}`,
    options: OptionsWithMeta
): string
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.