Skip to content

Sending the transaction to the node

weegee edited this page Nov 20, 2023 · 3 revisions

To send the transaction to the node, obtain the rkyv serialized Unproven Transaction which can be obtained by calling execute in ffi.rs.

This will give us a rkyv serialized unproven transaction.

Then we convert the rkyv serialized unproven transaction to var bytes using

const args = JSON.stringify({
   bytes: unprovenTx,
});

const txSerialized = jsonFromBytes(call(wasm, args, wasm.unproven_tx_to_bytes)).serialized;

Now we can send it to the node for proving!

To obtain the proof, send the prove_execute request to the node

// send the prove execute
const proofReq = await request(
      varBytes,
      "prove_execute",
      false,
      undefined,
      "rusk",
      "2"
);
// get the response bytes 
const buffer = await proofReq.arrayBuffer();
const bytes = new Uint8Array(buffer);

// call the prove_tx function 
const args = JSON.stringify({
    unproven_tx: unprovenTx,
    proof: Array.from(proof),
});

const provedTx = jsonFromBytes(call(wasm, args, wasm.prove_tx));

Now you have to preverify the transaction before propogating it to the blockchain

// pre verify the proved tx
const preVerifyReq = await request(
      provedTx,
      "preverify",
      false,
      undefined,
      "rusk",
      "2"
);

// log the status of the request (should be 200)
console.log("preverify request status code: " + preVerifyReq.status);

// propogate the proved tx
const propogateReq = await request(
      tx,
      "propagate_tx",
      false,
      undefined,
      "Chain",
      "2"
);

console.log("propogating chain request status: " + propogateReq.status);