Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
47c9ffc
Add upward type
soerenbf Aug 29, 2025
797c4de
Update block item summary
soerenbf Aug 29, 2025
386c1e2
Add docs explaining possible unknowns
soerenbf Sep 1, 2025
aa680e3
Update changelog
soerenbf Sep 1, 2025
cc18768
Fix unit test compile errors
soerenbf Sep 1, 2025
d1490dd
Update token and stake related events with unknown variants
soerenbf Sep 2, 2025
b14bf79
Update examples
soerenbf Sep 2, 2025
c7ed2a2
Update changelog
soerenbf Sep 2, 2025
14ee429
Wrap response for special events in `Upward`
soerenbf Sep 2, 2025
a771112
Wrap pending update effects in `Upward`
soerenbf Sep 2, 2025
c465f14
add jsdoc
soerenbf Sep 2, 2025
d18dd35
Add jsdoc
soerenbf Sep 2, 2025
76049de
Wrap `UpdateInstructionPayload` in `Upward` for read-only types
soerenbf Sep 2, 2025
2ec30f0
JSDoc
soerenbf Sep 2, 2025
5804114
..
soerenbf Sep 2, 2025
d494537
Changelog
soerenbf Sep 2, 2025
7596357
Merge pull request #481 from Concordium/forwards-comp/block-item-summary
soerenbf Sep 2, 2025
7218e48
Restructure token module types + add reject reason
soerenbf Sep 3, 2025
5fb2020
Fix build
soerenbf Sep 3, 2025
a41cc64
Forward compat for parsing encoded token module events
soerenbf Sep 3, 2025
8b9c0cc
Add missing jsdoc
soerenbf Sep 3, 2025
5fb33b0
Merge pull request #484 from Concordium/forward-comp/chain-updates
soerenbf Sep 3, 2025
3ca55b8
Merge pull request #483 from Concordium/forward-comp/special-events
soerenbf Sep 3, 2025
c3a6e9b
Merge branch 'feature/forwards-compatibility' into forward-comp/events
soerenbf Sep 3, 2025
c3e2080
Merge pull request #482 from Concordium/forward-comp/events
soerenbf Sep 3, 2025
3615c99
Wrapped NodeInfoConsensusStatus and NodeCatchupStatus with Upward
Sep 3, 2025
f377416
Move cbor decode functionality into its own file
soerenbf Sep 3, 2025
fa505a4
ran Prettier for some style issue
Sep 3, 2025
bd22379
Add parser function for token module reject reasons
soerenbf Sep 3, 2025
46fe10c
Wrapped Upward around PassiveCommitteeInfo
Sep 3, 2025
859210a
ran prettier
Sep 3, 2025
f562b2c
Parse token ops
soerenbf Sep 3, 2025
40ae3c8
Merge pull request #491 from Concordium/forward-com/COR-1841-NodeCatc…
rbaconcordium Sep 3, 2025
9b043f9
Merge branch 'feature/forwards-compatibility' into forward-com/COR-18…
rbaconcordium Sep 3, 2025
b5a9fb0
Merge pull request #493 from Concordium/forward-com/COR-1841-PassiveC…
rbaconcordium Sep 3, 2025
0450bed
changed to case undefined instead of default
Sep 4, 2025
5b015b4
Merge pull request #495 from Concordium/forward-comp/COR-1841-case-un…
rbaconcordium Sep 4, 2025
23cdfc4
Align tests to introduction of unknown variants + `TokenModuleRejectR…
soerenbf Sep 4, 2025
0a81229
Add option to `Cbor.decode` into type `TokenOperation[]`
soerenbf Sep 4, 2025
ce8b8e4
Update changelog
soerenbf Sep 4, 2025
600f360
Add missing jsdoc
soerenbf Sep 4, 2025
460aab9
Wrap Upward around RejectReason
Sep 4, 2025
cb31f32
Fix examples
soerenbf Sep 4, 2025
0fc90f7
Fix tests
soerenbf Sep 4, 2025
0203bce
wrapped Upward for RejectReason in blockItemSummary
Sep 4, 2025
4f20370
Merge pull request #488 from Concordium/cbor-types-refactor
soerenbf Sep 4, 2025
6ce0679
Update examples/nodejs/client/getBlockItemStatus.ts
rbaconcordium Sep 4, 2025
119cf44
Update examples/nodejs/plt/update-supply.ts
rbaconcordium Sep 4, 2025
8848c47
Update examples/nodejs/plt/transfer.ts
rbaconcordium Sep 4, 2025
c88c599
Update examples/nodejs/plt/modify-list.ts
rbaconcordium Sep 4, 2025
f8f514a
Update examples/nodejs/plt/pause.ts
rbaconcordium Sep 4, 2025
181caaf
Update packages/sdk/src/types/blockItemSummary.ts
rbaconcordium Sep 4, 2025
5e2e46f
Update packages/sdk/src/types.ts
rbaconcordium Sep 4, 2025
87ac9c8
fmt
soerenbf Sep 4, 2025
383ad91
Merge pull request #497 from Concordium/forward-com/COR-1834-Reject-R…
rbaconcordium Sep 5, 2025
3e9ef84
Wrap Upward around RewardStatus
Sep 5, 2025
a1ba8eb
Amended as per feedbacks
Sep 5, 2025
ab2ea43
Formating of file
Sep 5, 2025
a5ccd88
Add unknown variants to fields to `AccountInfo` (#498)
soerenbf Sep 5, 2025
ba903c4
Merge branch 'feature/forwards-compatibility' into forward-comp/COR-1…
rbaconcordium Sep 5, 2025
2fa7b5a
Merge pull request #503 from Concordium/forward-comp/COR-1837-Reward-…
rbaconcordium Sep 5, 2025
1ad179e
Forward comp/token cbor types (#492)
soerenbf Sep 8, 2025
d9f4718
Forward comp/contract types (#499)
soerenbf Sep 8, 2025
e0c5a9a
Forward comp/creds (#502)
soerenbf Sep 9, 2025
bb0b35b
Merge pull request #486 from Concordium/feature/forwards-compatibility
soerenbf Sep 9, 2025
ebacd47
Merge branch 'release/sdk/11' into sdk-11-merge-main
soerenbf Sep 9, 2025
42ef4f3
Merge branch 'release/sdk/11' into cis7-refactor
soerenbf Sep 9, 2025
7331660
Fix build
soerenbf Sep 9, 2025
da48b66
Merge pull request #509 from Concordium/sdk-11-merge-main
soerenbf Sep 9, 2025
09709e5
Merge branch 'release/sdk/11' into cis7-refactor
soerenbf Sep 9, 2025
fa16240
CIS-7/Add distinction in representation of cis7 accounts and tokenhol…
soerenbf Sep 10, 2025
254cefa
CIS-7/contract address (#506)
soerenbf Sep 10, 2025
9bdcf83
Merge branch 'main' into sdk-11-merge-main
soerenbf Sep 10, 2025
9b2abd1
Merge pull request #510 from Concordium/sdk-11-merge-main
soerenbf Sep 10, 2025
6cdb08f
Merge branch 'release/sdk/11' into cis7-refactor
soerenbf Sep 11, 2025
62c18c0
Merge branch 'cis7-refactor' of github.com:Concordium/concordium-node…
soerenbf Sep 11, 2025
86747f6
Don't interpret subindex, allow read of `undefined` value
soerenbf Sep 11, 2025
4e68f26
Ensure `CborContractAddress` preserves original structure when parsed
soerenbf Sep 11, 2025
a226868
Ensure `CborAccountAddress` preserves original structure
soerenbf Sep 11, 2025
e0ad7a3
Fix build
soerenbf Sep 11, 2025
ffb0217
Merge pull request #505 from Concordium/cis7-refactor
soerenbf Sep 11, 2025
265b4ad
Make everything optional for token init params + module state, accord…
soerenbf Sep 25, 2025
d80f5e0
Remove console.log
soerenbf Sep 25, 2025
758b3e4
Ignore npm links returning 403 by the link checker
soerenbf Sep 26, 2025
e879f5f
Merge pull request #514 from Concordium/cis-7-implementation
soerenbf Sep 26, 2025
cf2c00e
Align cis-7 decode function with changes to init params and module state
soerenbf Sep 27, 2025
4efc204
Merge branch 'release/sdk/11' into cis-7-implementation
soerenbf Sep 27, 2025
a3e6592
Improve decode error messages
soerenbf Sep 29, 2025
d6c6415
Merge pull request #515 from Concordium/cis-7-implementation
soerenbf Sep 29, 2025
c662267
Sdk 11 merge main (#534)
soerenbf Oct 8, 2025
962979d
Forward comp/migration guide (#537)
soerenbf Oct 9, 2025
3cb293d
Merge branch 'main' into sdk-11-merge-main
soerenbf Oct 13, 2025
53eda7a
Merge branch 'main' into sdk-11-merge-main
soerenbf Oct 13, 2025
4b0dc5a
fmt
soerenbf Oct 13, 2025
9929fef
Merge pull request #558 from Concordium/sdk-11-merge-main
soerenbf Oct 13, 2025
ce3abbb
sdk version bump to 11
soerenbf Oct 13, 2025
6a1f369
Merge pull request #559 from Concordium/sdk/version-bump
soerenbf Oct 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions docs/pages/misc-pages/upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
## web SDK version 11

This version of the web SDK focuses on forward compatibility, i.e. making it easier to keep applications and services
running through updates to the integration point (Concordium nodes).

### Motivation

Up until this release, certain extensions to the Concordium Node API have resulted in the SDK failing to parse query
responses, resulting in the entire query failing. This is the case even for the larger queries where the unknown/missing
information is only a small part of the response preventing the application to access the entire response.
Usually the fix was to update the SDK to a newer version which know how to parse the new information, but this imposes
work for the ecosystem for every change in the API (usually part of protocol version updates).

This major release introduces `Upward<A>` a type wrapper representing information which might be extended in future version
of the API, providing a variant representing unknown information such that queries can provide partial information.
It makes potentially extended information explicit in the types and allows each application to decide how to handle the
case of new unknown data on a case by case basis.

### Handling `Upward`

Handling upward depends on what you want to achieve. If you're running a service that integrates with a Concordium node,
you might want to fail safely by handling unknown variants gracefully. If you're writing a script it's probably easier
to fail fast.

#### Fail safe

```ts
import { isKnown, type TransactionHash } from '@concordium/web-sdk';
...

const transactionSummary: Upward<BlockItemSummary> = ...

// branch on unknown
if (isKnown(transactionSummary)) {
// transactionSummary is statically known at this point
} else {
// handle the unknown case
console.warn('Encountered unknown transaction type.');
}

// Handle as optional
// `Unknown` variant is simply represented as `null` underneath.
const transactionHash: TransactionHash.Type | undefined = transactionSummary?.hash;
```

#### Fail fast

```ts
import { assertError, type TransactionHash } from '@concordium/web-sdk';
...

const transactionSummary: Upward<BlockItemSummary> = ...

// fail with an error message in case of the unexpected happening.
assertKnown(transctionSummary, 'Expected transaction type to be known');
// transactionSummary is known at this point on.

// or handle by simple null assertion, e.g. in the case where you just sent
// the transaction to a node.
handleKnownTransaction(transactionSummary!);
```

#### Optional + Unknown values

In the SDK, `undefined` is used to represent when an optional value is _not_ present and `null` is used to represent
unknown values. If you want to branch on these different cases, it can be handled by targeting thesee specific types:

```ts
const optionalUnknown: Upward<Value> | undefined = ...
switch (optionalUnknown) {
case undefined: ... // handle optionality
case null: ... // handle unknown variant
default: ... // at this point, we know the type is `Value`
}
```

## web SDK version 7

Several types have been replaced with a module containing the type itself together with functions for constructing and
Expand Down
7 changes: 3 additions & 4 deletions examples/nodejs/client/getBlockItemStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockItemStatus, CcdAmount, TransactionHash } from '@concordium/web-sdk';
import { BlockItemStatus, CcdAmount, TransactionHash, knownOrError } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -77,8 +77,7 @@ const client = new ConcordiumGRPCNodeClient(
if (blockItemStatus.status === 'finalized') {
console.log('blockItemStatus is "finalized" and therefore there is exactly one outcome \n');

const { summary } = blockItemStatus.outcome;

const summary = knownOrError(blockItemStatus.outcome.summary, 'unknown outcome encountered');
if (summary.type === 'accountTransaction') {
console.log('The block item is an account transaction');

Expand All @@ -95,7 +94,7 @@ const client = new ConcordiumGRPCNodeClient(
const { failedTransactionType, rejectReason } = summary;
console.log(
'Transaction of type "' + failedTransactionType + '" failed because:',
rejectReason.tag
rejectReason?.tag ?? 'unknown'
);
break;
default:
Expand Down
10 changes: 7 additions & 3 deletions examples/nodejs/client/getBlockSpecialEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockHash, BlockSpecialEvent } from '@concordium/web-sdk';
import { BlockHash, BlockSpecialEvent, Upward, isKnown } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -50,10 +50,14 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
(async () => {
// #region documentation-snippet
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const events: AsyncIterable<BlockSpecialEvent> = client.getBlockSpecialEvents(blockHash);
const events: AsyncIterable<Upward<BlockSpecialEvent>> = client.getBlockSpecialEvents(blockHash);
// #endregion documentation-snippet

for await (const event of events) {
console.dir(event, { depth: null, colors: true });
if (!isKnown(event)) {
console.warn('Unknown event encountered');
} else {
console.dir(event, { depth: null, colors: true });
}
}
})();
10 changes: 7 additions & 3 deletions examples/nodejs/client/getBlockTransactionEvents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockHash, BlockItemSummary } from '@concordium/web-sdk';
import { BlockHash, BlockItemSummary, Upward, isKnown } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -48,10 +48,14 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
(async () => {
// #region documentation-snippet
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const events: AsyncIterable<BlockItemSummary> = client.getBlockTransactionEvents(blockHash);
const events: AsyncIterable<Upward<BlockItemSummary>> = client.getBlockTransactionEvents(blockHash);
// #endregion documentation-snippet

for await (const event of events) {
console.dir(event, { depth: null, colors: true });
if (isKnown(event)) {
console.dir(event, { depth: null, colors: true });
} else {
console.warn('Encountered unknown event');
}
}
})();
7 changes: 6 additions & 1 deletion examples/nodejs/client/getTokenomicsInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockHash } from '@concordium/web-sdk';
import { BlockHash, isKnown } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -55,6 +55,11 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c

// Protocol version 4 expanded the amount of information in the response, so one should check the type to access that.
// This information includes information about the payday and total amount of funds staked.
if (!isKnown(tokenomics)) {
console.warn('Unknown tokenomics version found');
return;
}

if (tokenomics.version === 1) {
console.log('Next payday time:', tokenomics.nextPaydayTime);
console.log('Total staked amount by bakers and delegators', tokenomics.totalStakedCapital);
Expand Down
3 changes: 2 additions & 1 deletion examples/nodejs/client/invokeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Parameter,
ReceiveName,
ReturnValue,
Upward,
} from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
Expand Down Expand Up @@ -124,7 +125,7 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
console.log('The return value of the invoked method:', ReturnValue.toHexString(returnValue));
}

const events: ContractTraceEvent[] = result.events;
const events: Upward<ContractTraceEvent>[] = result.events;
console.log('A list of effects that the update would have:');
console.dir(events, { depth: null, colors: true });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountAddress, isRpcError } from '@concordium/web-sdk';
import { AccountAddress, isKnown, isRpcError } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -75,6 +75,9 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c

// If account is not a genesis account print account creation transaction hash
for await (const summary of summaries) {
if (!isKnown(summary)) {
continue;
}
if (summary.type === 'accountCreation' && AccountAddress.equals(summary.address, account)) {
console.log('Hash of transaction that created the account:', summary.hash);
}
Expand Down
11 changes: 10 additions & 1 deletion examples/nodejs/composed-examples/initAndUpdateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
affectedContracts,
buildAccountSigner,
deserializeReceiveReturnValue,
isKnown,
knownOrError,
parseWallet,
serializeInitContractParameters,
serializeUpdateContractParameters,
Expand Down Expand Up @@ -118,7 +120,14 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
const initStatus = await client.waitForTransactionFinalization(initTrxHash);
console.dir(initStatus, { depth: null, colors: true });

const contractAddress = affectedContracts(initStatus.summary)[0];
if (!isKnown(initStatus.summary)) {
throw new Error('Unexpected transaction outcome');
}

const contractAddress = knownOrError(
affectedContracts(initStatus.summary)[0],
'Expected contract init event to be known'
);

// #endregion documentation-snippet-init-contract

Expand Down
5 changes: 4 additions & 1 deletion examples/nodejs/composed-examples/listInitialAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unwrap } from '@concordium/web-sdk';
import { isKnown, unwrap } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -71,6 +71,9 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
// Get transactions for block
const trxStream = client.getBlockTransactionEvents(block.hash);
for await (const trx of trxStream) {
if (!isKnown(trx)) {
continue;
}
if (trx.type === 'accountCreation' && trx.credentialType === 'initial') {
initAccounts.push(trx.address);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountAddress, isTransferLikeSummary, unwrap } from '@concordium/web-sdk';
import { AccountAddress, isKnown, isTransferLikeSummary, unwrap } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -75,6 +75,9 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c

// For each transaction in the block:
trxLoop: for await (const trx of trxStream) {
if (!isKnown(trx)) {
continue;
}
if (isTransferLikeSummary(trx)) {
const trxAcc = trx.sender;

Expand Down
20 changes: 13 additions & 7 deletions examples/nodejs/plt/modify-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import {
TransactionEventTag,
TransactionKindString,
TransactionSummaryType,
isKnown,
serializeAccountTransactionPayload,
} from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import {
Cbor,
CborAccountAddress,
Token,
TokenHolder,
TokenId,
TokenListUpdate,
TokenOperation,
TokenOperationType,
createTokenUpdatePayload,
parseTokenModuleEvent,
} from '@concordium/web-sdk/plt';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -105,7 +107,7 @@ const client = new ConcordiumGRPCNodeClient(

// parse the arguments
const tokenId = TokenId.fromString(id);
const targetAddress = TokenHolder.fromAccountAddress(AccountAddress.fromBase58(address));
const targetAddress = AccountAddress.fromBase58(address);

if (walletFile !== undefined) {
// Read wallet-file
Expand Down Expand Up @@ -137,22 +139,26 @@ const client = new ConcordiumGRPCNodeClient(
const result = await client.waitForTransactionFinalization(transaction);
console.log('Transaction finalized:', result);

if (!isKnown(result.summary)) {
throw new Error('Unexpected transaction outcome');
}

if (result.summary.type !== TransactionSummaryType.AccountTransaction) {
throw new Error('Unexpected transaction type: ' + result.summary.type);
}

switch (result.summary.transactionType) {
case TransactionKindString.TokenUpdate:
result.summary.events.forEach((e) => {
result.summary.events.filter(isKnown).forEach((e) => {
if (e.tag !== TransactionEventTag.TokenModuleEvent) {
throw new Error('Unexpected event type: ' + e.tag);
}
console.log('Token module event:', e, Cbor.decode(e.details, 'TokenListUpdateEventDetails'));
console.log('Token module event:', parseTokenModuleEvent(e));
});
break;
case TransactionKindString.Failed:
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
if (result.summary.rejectReason?.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
}
const details = Cbor.decode(result.summary.rejectReason.contents.details);
console.error(result.summary.rejectReason.contents, details);
Expand All @@ -167,7 +173,7 @@ const client = new ConcordiumGRPCNodeClient(
const operationType = `${action}-${list}-list` as TokenOperationType;
// Or from a wallet perspective:
// Create list payload. The payload is the same for both add and remove operations on all lists.
const listPayload: TokenListUpdate = { target: targetAddress };
const listPayload: TokenListUpdate = { target: CborAccountAddress.fromAccountAddress(targetAddress) };
const listOperation = {
[operationType]: listPayload,
} as TokenOperation; // Normally the cast is not necessary unless done in the same dynamic way as here.
Expand Down
22 changes: 17 additions & 5 deletions examples/nodejs/plt/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import {
TransactionEventTag,
TransactionKindString,
TransactionSummaryType,
isKnown,
serializeAccountTransactionPayload,
} from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { Cbor, Token, TokenId, TokenOperation, createTokenUpdatePayload } from '@concordium/web-sdk/plt';
import {
Cbor,
Token,
TokenId,
TokenOperation,
createTokenUpdatePayload,
parseTokenModuleEvent,
} from '@concordium/web-sdk/plt';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';

Expand Down Expand Up @@ -102,22 +110,26 @@ const client = new ConcordiumGRPCNodeClient(
const result = await client.waitForTransactionFinalization(transaction);
console.log('Transaction finalized:', result);

if (!isKnown(result.summary)) {
throw new Error('Unexpected transaction outcome');
}

if (result.summary.type !== TransactionSummaryType.AccountTransaction) {
throw new Error('Unexpected transaction type: ' + result.summary.type);
}

switch (result.summary.transactionType) {
case TransactionKindString.TokenUpdate:
result.summary.events.forEach((e) => {
result.summary.events.filter(isKnown).forEach((e) => {
if (e.tag !== TransactionEventTag.TokenModuleEvent) {
throw new Error('Unexpected event type: ' + e.tag);
}
console.log('Token module event:', e, Cbor.decode(e.details, 'TokenPauseEventDetails'));
console.log('Token module event:', parseTokenModuleEvent(e));
});
break;
case TransactionKindString.Failed:
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
if (result.summary.rejectReason?.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
}
const details = Cbor.decode(result.summary.rejectReason.contents.details);
console.error(result.summary.rejectReason.contents, details);
Expand Down
Loading