Skip to content

Commit

Permalink
docs(interacting-with-zkapps-server-side.mdx): update isSuccess to st…
Browse files Browse the repository at this point in the history
…atus for transaction status check

refactor(interact.ts, main.ts, utils.ts): replace isSuccess with status for transaction status validation
feat(interacting-with-zkapps-server-side.mdx): enhance explanation of pendingTransaction properties
refactor(interacting-with-zkApps-server-side): update isSuccess to status for transaction status check
  • Loading branch information
MartinMinkov committed Mar 6, 2024
1 parent ecfe56f commit 7ee778a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/zkapps/tutorials/interacting-with-zkapps-server-side.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ To send an update transaction, perform the following steps:
When sending the transaction using `transaction.send()`, an object called `pendingTransaction` is returned and provides information about how the transaction went and waits for inclusion in a block:

```ts
if (!pendingTransaction.isSuccess) {
if (pendingTransaction.status === "rejected") {
console.log('error sending transaction (see above)');
process.exit(0);
}
Expand All @@ -270,9 +270,9 @@ console.log(`updated state! ${await zkapp.num.fetch()}`);

This code uses several functionalities of the pending transaction:

- `pendingTransaction.isSuccess` is a boolean for whether the transaction was successful. Most invalid transactions are immediately rejected by the GraphQL endpoint with `isSuccess === false`.
- `pendingTransaction.status indicates the initial processing status of the transaction, with pending signifying that the transaction has been accepted for processing by the network, and rejected indicating that the transaction was immediately deemed invalid and rejected by the GraphQL endpoint.
- `pendingTransaction.hash` is the transaction hash that you can use to look up the transaction in a block explorer. If the transaction failed, it returns `undefined`.
- `pendingTransaction.wait()` is especially useful as it returns a promise that resolves `utils.ts` after the transaction is included in the latest block on the network. This takes several minutes, so you might not want to block the main thread on this in a real application.
- `pendingTransaction.wait()` is especially useful as it returns a promise that resolves whether a transaction is included into a block or rejected. This takes several minutes, so you might not want to block the main thread on this in a real application.

Finally, after the transaction was successfully applied on the Mina blockchain, you can double-check that your state was updated by fetching it again with `zkapp.num.fetch()`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ try {
} catch (err) {
console.log(err);
}
if (sentTx.isSuccess !== undefined) {
if (sentTx.status === 'pending') {
console.log(`
Success! Update transaction sent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const SERVER_ADDRESS = 'http://localhost:3001';
const res = await deploy_txn.send();

if (!USE_LOCAL_BLOCKCHAIN) {
if (!res.isSuccess) {
if (res.status === 'rejected') {
console.log('error sending transaction (see above)');
} else {
console.log(
Expand Down Expand Up @@ -196,7 +196,7 @@ const SERVER_ADDRESS = 'http://localhost:3001';
const res = await txn1.send();

if (!USE_LOCAL_BLOCKCHAIN) {
if (!res.isSuccess) {
if (res.status === 'rejected') {
console.log('error sending transaction (see above)');
} else {
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const makeAndSendTransaction = async <State extends ToString>({

console.log('Sending the transaction...');
const res = await transaction.send();
if (!res.isSuccess) {
if (res.status === 'rejected') {
console.log('error sending transaction (see above)');
} else {
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ let pendingTransaction = await transaction.send();

// ----------------------------------------------------

if (!pendingTransaction.isSuccess) {
if (pendingTransaction.status === 'rejected') {
console.log('error sending transaction (see above)');
process.exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function deploy(

console.log('Sending the deploy transaction...');
const res = await transaction.send();
if (!res.isSuccess) {
if (res.status === 'rejected') {
console.log('error sending transaction (see above)');
} else {
console.log(
Expand Down

0 comments on commit 7ee778a

Please sign in to comment.