Skip to content

Commit

Permalink
feat(simple-tx): showcase mempool endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed May 23, 2023
1 parent 3b014b7 commit 6b21dc7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions examples/simple-transaction/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const run = async () => {
}

// Prepare transaction
const { txHash, txBody } = composeTransaction(
const { txBody } = composeTransaction(
address,
OUTPUT_ADDRESS,
OUTPUT_AMOUNT,
Expand All @@ -83,14 +83,20 @@ const run = async () => {

// Push transaction to network
try {
const res = await client.txSubmit(transaction.to_bytes());
if (res) {
console.log(`Transaction successfully submitted: ${txHash}`);
}
// txSubmit endpoint returns transaction hash on successful submit
const txHash = await client.txSubmit(transaction.to_bytes());

// Before the tx is included in a block it is a waiting room known as mempool
// Retrieve transaction from Blockfrost Mempool
const mempoolTx = await client.mempoolTx(txHash);
console.log("Mempool Tx:");
console.log(JSON.stringify(mempoolTx, undefined, 4));

console.log(`Transaction successfully submitted: ${txHash}\n`);
} catch (error) {
// submit could fail if the transactions is rejected by cardano node
if (error instanceof BlockfrostServerError && error.status_code === 400) {
console.log(`Transaction ${txHash} rejected`);
console.log(`Transaction rejected`);
// Reason for the rejection is in error.message
console.log(error.message);
} else {
Expand Down

0 comments on commit 6b21dc7

Please sign in to comment.