Skip to content

Creating an unproven transaction

weegee edited this page Nov 18, 2023 · 2 revisions

To create an unproven transaction, you have to call execute() in ffi.rs. This will return the bytes of the unproven transaction which can be stored in a medium to be later sent to the network as convenient.

To send the transaction to the blockchain, you have to convert the bytes of the unproven transaction and convert it to var bytes using the unproven_tx_to_bytes in compact/tx.rs. The output of this function can be directly sent through the node.

Following example in javascript

// Prepare arguments for the execute function
const args = JSON.stringify({
      call: callData,
      crossover: crossover,
      seed: seed,
      fee: fee,
      rng_seed: Array.from(rng_seed),
      inputs: inputs,
      refund: psk,
      output: output,
      openings: openingsSerialized,
      sender_index: sender_index,
      gas_limit: gas_limit,
      gas_price: gas_price,
});
// get the unproven transaction from the execute, store this value 
// for later proving from the node
const unprovenTx = jsonFromBytes(call(wasm, args, wasm.execute)).tx;

// get the unproven transaction by calling `wasm.unproven_tx_to_bytes`
const varBytes = getUnprovenTxVarBytes(wasm, unprovenTx);

// Send it to the node if you want
const proofReq = await request(
      varBytes,
      "prove_execute",
      false,
      undefined,
      "rusk",
      "2"
);

... preverify and propogate request to the node...
Clone this wiki locally