New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@concordium/node-sdk

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@concordium/node-sdk - npm Package Compare versions

Comparing version

to
0.2.4

lib/src/types/Memo.d.ts

17

lib/src/accountTransactions.d.ts
import { Buffer } from 'buffer/';
import { AccountTransactionPayload, AccountTransactionType, SimpleTransfer } from './types';
interface AccountTransactionHandler {
serialize: (payload: AccountTransactionPayload) => Buffer;
getBaseEnergyCost: (payload?: AccountTransactionPayload) => bigint;
import { AccountTransactionPayload, AccountTransactionType, SimpleTransferPayload, SimpleTransferWithMemoPayload } from './types';
interface AccountTransactionHandler<PayloadType extends AccountTransactionPayload = AccountTransactionPayload> {
serialize: (payload: PayloadType) => Buffer;
getBaseEnergyCost: (payload?: PayloadType) => bigint;
}
export declare class SimpleTransferHandler implements AccountTransactionHandler {
export declare class SimpleTransferHandler implements AccountTransactionHandler<SimpleTransferWithMemoPayload> {
getBaseEnergyCost(): bigint;
serialize(transfer: SimpleTransfer): Buffer;
serialize(transfer: SimpleTransferPayload): Buffer;
}
export declare class SimpleTransferWithMemoHandler extends SimpleTransferHandler implements AccountTransactionHandler<SimpleTransferWithMemoPayload> {
serialize(transfer: SimpleTransferWithMemoPayload): Buffer;
}
export declare function getAccountTransactionHandler(type: AccountTransactionType.SimpleTransfer): SimpleTransferHandler;
export declare function getAccountTransactionHandler(type: AccountTransactionType.SimpleTransferWithMemo): SimpleTransferWithMemoHandler;
export declare function getAccountTransactionHandler(type: AccountTransactionType): AccountTransactionHandler;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAccountTransactionHandler = exports.SimpleTransferHandler = void 0;
exports.getAccountTransactionHandler = exports.SimpleTransferWithMemoHandler = exports.SimpleTransferHandler = void 0;
const buffer_1 = require("buffer/");

@@ -18,11 +18,26 @@ const serializationHelpers_1 = require("./serializationHelpers");

exports.SimpleTransferHandler = SimpleTransferHandler;
class SimpleTransferWithMemoHandler extends SimpleTransferHandler {
serialize(transfer) {
const serializedToAddress = transfer.toAddress.decodedAddress;
const serializedMemo = serializationHelpers_1.encodeMemo(transfer.memo);
const serializedAmount = serializationHelpers_1.encodeWord64(transfer.amount.microGtuAmount);
return buffer_1.Buffer.concat([
serializedToAddress,
serializedMemo,
serializedAmount,
]);
}
}
exports.SimpleTransferWithMemoHandler = SimpleTransferWithMemoHandler;
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
function getAccountTransactionHandler(type) {
const accountTransactionHandlerMap = new Map();
accountTransactionHandlerMap.set(types_1.AccountTransactionType.SimpleTransfer, new SimpleTransferHandler());
const handler = accountTransactionHandlerMap.get(type);
if (!handler) {
throw new Error('The handler map is missing the provided type: ' + type);
switch (type) {
case types_1.AccountTransactionType.SimpleTransfer:
return new SimpleTransferHandler();
case types_1.AccountTransactionType.SimpleTransferWithMemo:
return new SimpleTransferWithMemoHandler();
default:
throw new Error('The provided type does not have a handler: ' + type);
}
return handler;
}
exports.getAccountTransactionHandler = getAccountTransactionHandler;

@@ -69,2 +69,3 @@ "use strict";

const response = await this.sendRequest(this.client.getAccountInfo, getAddressInfoRequest);
const datePropertyKeys = ['timestamp'];
const bigIntPropertyKeys = [

@@ -78,3 +79,3 @@ 'accountAmount',

];
return util_1.unwrapJsonResponse(response, util_1.buildJsonResponseReviver([], bigIntPropertyKeys), util_1.intToStringTransformer(bigIntPropertyKeys));
return util_1.unwrapJsonResponse(response, util_1.buildJsonResponseReviver(datePropertyKeys, bigIntPropertyKeys), util_1.intToStringTransformer(bigIntPropertyKeys));
}

@@ -81,0 +82,0 @@ /**

@@ -11,1 +11,2 @@ import ConcordiumNodeClient from './client';

export { TransactionExpiry } from './types/transactionExpiry';
export { Memo } from './types/Memo';

@@ -16,3 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionExpiry = exports.GtuAmount = exports.AccountAddress = exports.sha256 = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = exports.ConcordiumNodeClient = void 0;
exports.Memo = exports.TransactionExpiry = exports.GtuAmount = exports.AccountAddress = exports.sha256 = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = exports.ConcordiumNodeClient = void 0;
const client_1 = __importDefault(require("./client"));

@@ -32,1 +32,3 @@ exports.ConcordiumNodeClient = client_1.default;

Object.defineProperty(exports, "TransactionExpiry", { enumerable: true, get: function () { return transactionExpiry_1.TransactionExpiry; } });
var Memo_1 = require("./types/Memo");
Object.defineProperty(exports, "Memo", { enumerable: true, get: function () { return Memo_1.Memo; } });

@@ -51,4 +51,4 @@ "use strict";

};
const putCredentialSignatures = (credSig) => serializationHelpers_1.serializeMap(credSig, serializationHelpers_1.encodeUint8, serializationHelpers_1.encodeUint8, putSignature);
return serializationHelpers_1.serializeMap(signatures, serializationHelpers_1.encodeUint8, serializationHelpers_1.encodeUint8, putCredentialSignatures);
const putCredentialSignatures = (credSig) => serializationHelpers_1.serializeMap(credSig, serializationHelpers_1.encodeWord8, serializationHelpers_1.encodeWord8FromString, putSignature);
return serializationHelpers_1.serializeMap(signatures, serializationHelpers_1.encodeWord8, serializationHelpers_1.encodeWord8FromString, putCredentialSignatures);
}

@@ -65,3 +65,3 @@ exports.serializeAccountTransactionSignature = serializeAccountTransactionSignature;

function serializeAccountTransaction(accountTransaction, signatures) {
const serializedBlockItemKind = serializationHelpers_1.encodeUint8(types_1.BlockItemKind.AccountTransactionKind);
const serializedBlockItemKind = serializationHelpers_1.encodeWord8(types_1.BlockItemKind.AccountTransactionKind);
const serializedAccountTransactionSignatures = serializeAccountTransactionSignature(signatures);

@@ -127,5 +127,5 @@ const serializedType = serializeAccountTransactionType(accountTransaction.type);

const serializedAccountTransaction = serializeAccountTransaction(accountTransaction, signatures);
const serializedVersion = serializationHelpers_1.encodeUint8(0);
const serializedVersion = serializationHelpers_1.encodeWord8(0);
return buffer_1.Buffer.concat([serializedVersion, serializedAccountTransaction]);
}
exports.serializeAccountTransactionForSubmission = serializeAccountTransactionForSubmission;
import { Buffer } from 'buffer/';
export declare function serializeMap<K extends string | number | symbol, T>(map: Record<K, T>, encodeSize: (size: number) => Buffer, encodeKey: (k: K) => Buffer, encodeValue: (t: T) => Buffer): Buffer;
import { Memo } from './types/Memo';
export declare function serializeMap<K extends string | number | symbol, T>(map: Record<K, T>, encodeSize: (size: number) => Buffer, encodeKey: (k: string) => Buffer, encodeValue: (t: T) => Buffer): Buffer;
/**

@@ -16,2 +17,8 @@ * Encodes a 64 bit unsigned integer to a Buffer using big endian.

/**
* Encodes a 16 bit unsigned integer to a Buffer using big endian.
* @param value a 16 bit integer
* @returns big endian serialization of the input
*/
export declare function encodeWord16(value: number): Buffer;
/**
* Encodes a 8 bit unsigned integer to a Buffer using big endian.

@@ -21,2 +28,9 @@ * @param value a 8 bit integer

*/
export declare function encodeUint8(value: number): Buffer;
export declare function encodeWord8(value: number): Buffer;
export declare function encodeWord8FromString(value: string): Buffer;
/**
* Encodes a memo.
* @param memo Memo containing the memo bytes.
* @returns Buffer containing the length of the memo bytes and the memo bytes.
*/
export declare function encodeMemo(memo: Memo): Buffer;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeUint8 = exports.encodeWord32 = exports.encodeWord64 = exports.serializeMap = void 0;
exports.encodeMemo = exports.encodeWord8FromString = exports.encodeWord8 = exports.encodeWord16 = exports.encodeWord32 = exports.encodeWord64 = exports.serializeMap = void 0;
const buffer_1 = require("buffer/");

@@ -36,3 +36,3 @@ function serializeMap(map, encodeSize, encodeKey, encodeValue) {

function encodeWord32(value) {
if (value > 4294967295 || value < 0) {
if (value > 4294967295 || value < 0 || !Number.isInteger(value)) {
throw new Error('The input has to be a 32 bit unsigned integer but it was: ' + value);

@@ -47,2 +47,17 @@ }

/**
* Encodes a 16 bit unsigned integer to a Buffer using big endian.
* @param value a 16 bit integer
* @returns big endian serialization of the input
*/
function encodeWord16(value) {
if (value > 65535 || value < 0 || !Number.isInteger(value)) {
throw new Error('The input has to be a 16 bit unsigned integer but it was: ' + value);
}
const arr = new ArrayBuffer(2);
const view = new DataView(arr);
view.setUint16(0, value, false);
return buffer_1.Buffer.from(new Uint8Array(arr));
}
exports.encodeWord16 = encodeWord16;
/**
* Encodes a 8 bit unsigned integer to a Buffer using big endian.

@@ -52,5 +67,22 @@ * @param value a 8 bit integer

*/
function encodeUint8(value) {
function encodeWord8(value) {
if (value > 255 || value < 0 || !Number.isInteger(value)) {
throw new Error('The input has to be a 16 bit unsigned integer but it was: ' + value);
}
return buffer_1.Buffer.from(buffer_1.Buffer.of(value));
}
exports.encodeUint8 = encodeUint8;
exports.encodeWord8 = encodeWord8;
function encodeWord8FromString(value) {
return encodeWord8(Number(value));
}
exports.encodeWord8FromString = encodeWord8FromString;
/**
* Encodes a memo.
* @param memo Memo containing the memo bytes.
* @returns Buffer containing the length of the memo bytes and the memo bytes.
*/
function encodeMemo(memo) {
const length = encodeWord16(memo.memo.length);
return buffer_1.Buffer.concat([length, memo.memo]);
}
exports.encodeMemo = encodeMemo;
import { AccountAddress } from './types/accountAddress';
import { GtuAmount } from './types/gtuAmount';
import { Memo } from './types/Memo';
import { TransactionExpiry } from './types/transactionExpiry';

@@ -65,11 +66,85 @@ /**

}
export interface EventResult {
outcome: string;
events: (TransactionEvent | TransferredEvent | UpdatedEvent)[];
export interface TransferredWithScheduleEvent {
tag: 'TransferredWithSchedule';
to: AddressAccount;
from: AddressAccount;
amount: ReleaseSchedule[];
}
interface TransactionSummaryType {
export interface MemoEvent {
tag: 'TransferMemo';
memo: string;
}
/**
* An enum containing all the possible reject reasons that can be
* received from a node as a response to a transaction submission.
*
* This should be kept in sync with the list of reject reasons
* found here: https://github.com/Concordium/concordium-base/blob/main/haskell-src/Concordium/Types/Execution.hs
*/
export declare enum RejectReasonTag {
ModuleNotWF = "ModuleNotWF",
ModuleHashAlreadyExists = "ModuleHashAlreadyExists",
InvalidAccountReference = "InvalidAccountReference",
InvalidInitMethod = "InvalidInitMethod",
InvalidReceiveMethod = "InvalidReceiveMethod",
InvalidModuleReference = "InvalidModuleReference",
InvalidContractAddress = "InvalidContractAddress",
RuntimeFailure = "RuntimeFailure",
AmountTooLarge = "AmountTooLarge",
SerializationFailure = "SerializationFailure",
OutOfEnergy = "OutOfEnergy",
RejectedInit = "RejectedInit",
RejectedReceive = "RejectedReceive",
NonExistentRewardAccount = "NonExistentRewardAccount",
InvalidProof = "InvalidProof",
AlreadyABaker = "AlreadyABaker",
NotABaker = "NotABaker",
InsufficientBalanceForBakerStake = "InsufficientBalanceForBakerStake",
StakeUnderMinimumThresholdForBaking = "StakeUnderMinimumThresholdForBaking",
BakerInCooldown = "BakerInCooldown",
DuplicateAggregationKey = "DuplicateAggregationKey",
NonExistentCredentialID = "NonExistentCredentialID",
KeyIndexAlreadyInUse = "KeyIndexAlreadyInUse",
InvalidAccountThreshold = "InvalidAccountThreshold",
InvalidCredentialKeySignThreshold = "InvalidCredentialKeySignThreshold",
InvalidEncryptedAmountTransferProof = "InvalidEncryptedAmountTransferProof",
InvalidTransferToPublicProof = "InvalidTransferToPublicProof",
EncryptedAmountSelfTransfer = "EncryptedAmountSelfTransfer",
InvalidIndexOnEncryptedTransfer = "InvalidIndexOnEncryptedTransfer",
ZeroScheduledAmount = "ZeroScheduledAmount",
NonIncreasingSchedule = "NonIncreasingSchedule",
FirstScheduledReleaseExpired = "FirstScheduledReleaseExpired",
ScheduledSelfTransfer = "ScheduledSelfTransfer",
InvalidCredentials = "InvalidCredentials",
DuplicateCredIDs = "DuplicateCredIDs",
NonExistentCredIDs = "NonExistentCredIDs",
RemoveFirstCredential = "RemoveFirstCredential",
CredentialHolderDidNotSign = "CredentialHolderDidNotSign",
NotAllowedMultipleCredentials = "NotAllowedMultipleCredentials",
NotAllowedToReceiveEncrypted = "NotAllowedToReceiveEncrypted",
NotAllowedToHandleEncrypted = "NotAllowedToHandleEncrypted"
}
export interface RejectReason {
tag: RejectReasonTag;
contents: any;
}
interface RejectedEventResult {
outcome: 'reject';
rejectReason: RejectReason;
}
interface SuccessfulEventResult {
outcome: 'success';
events: (TransactionEvent | TransferredEvent | UpdatedEvent | MemoEvent | TransferredWithScheduleEvent)[];
}
export declare type EventResult = SuccessfulEventResult | TransferWithMemoEventResult | RejectedEventResult;
interface BaseTransactionSummaryType {
type: 'accountTransaction' | 'credentialDeploymentTransaction' | 'updateTransaction';
}
export interface TransferWithMemoSummaryType extends BaseTransactionSummaryType {
contents: 'transferWithMemo';
}
export interface GenericTransactionSummaryType extends BaseTransactionSummaryType {
contents: string;
}
export interface TransactionSummary {
export interface BaseTransactionSummary {
sender?: string;

@@ -80,5 +155,17 @@ hash: string;

index: bigint;
type: TransactionSummaryType;
}
interface GenericTransactionSummary extends BaseTransactionSummary {
type: GenericTransactionSummaryType;
result: EventResult;
}
interface TransferWithMemoEventResult {
outcome: 'success';
events: [TransferredEvent, MemoEvent];
}
export interface TransferWithMemoTransactionSummary extends BaseTransactionSummary {
type: TransferWithMemoSummaryType;
result: TransferWithMemoEventResult;
}
export declare type TransactionSummary = GenericTransactionSummary | TransferWithMemoTransactionSummary;
export declare function instanceOfTransferWithMemoTransactionSummary(object: TransactionSummary): object is TransferWithMemoTransactionSummary;
export interface TransactionStatus {

@@ -246,7 +333,9 @@ status: TransactionStatusEnum;

amount: bigint;
transactions: any;
}
export interface ReleaseScheduleWithTransactions extends ReleaseSchedule {
transactions: string[];
}
export interface AccountReleaseSchedule {
total: bigint;
schedule: ReleaseSchedule[];
schedule: ReleaseScheduleWithTransactions[];
}

@@ -340,3 +429,6 @@ export interface AccountEncryptedAmount {

UpdateCredentials = 20,
RegisterData = 21
RegisterData = 21,
SimpleTransferWithMemo = 22,
EncryptedTransferWithMemo = 23,
TransferWithScheduleWithMemo = 24
}

@@ -354,9 +446,13 @@ export interface AccountTransactionHeader {

}
export interface SimpleTransfer {
export interface SimpleTransferPayload {
/** µGTU amount to transfer */
amount: GtuAmount;
/** the recipient of the transfer*/
/** the recipient of the transfer */
toAddress: AccountAddress;
}
export declare type AccountTransactionPayload = SimpleTransfer;
export interface SimpleTransferWithMemoPayload extends SimpleTransferPayload {
/** The bytes representation of the memo of the transaction */
memo: Memo;
}
export declare type AccountTransactionPayload = SimpleTransferPayload | SimpleTransferWithMemoPayload;
export interface AccountTransaction {

@@ -363,0 +459,0 @@ type: AccountTransactionType;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountTransactionType = exports.BlockItemKind = exports.TransactionStatusEnum = exports.AttributesKeys = void 0;
exports.AccountTransactionType = exports.BlockItemKind = exports.instanceOfTransferWithMemoTransactionSummary = exports.RejectReasonTag = exports.TransactionStatusEnum = exports.AttributesKeys = void 0;
var AttributesKeys;

@@ -26,2 +26,57 @@ (function (AttributesKeys) {

})(TransactionStatusEnum = exports.TransactionStatusEnum || (exports.TransactionStatusEnum = {}));
/**
* An enum containing all the possible reject reasons that can be
* received from a node as a response to a transaction submission.
*
* This should be kept in sync with the list of reject reasons
* found here: https://github.com/Concordium/concordium-base/blob/main/haskell-src/Concordium/Types/Execution.hs
*/
var RejectReasonTag;
(function (RejectReasonTag) {
RejectReasonTag["ModuleNotWF"] = "ModuleNotWF";
RejectReasonTag["ModuleHashAlreadyExists"] = "ModuleHashAlreadyExists";
RejectReasonTag["InvalidAccountReference"] = "InvalidAccountReference";
RejectReasonTag["InvalidInitMethod"] = "InvalidInitMethod";
RejectReasonTag["InvalidReceiveMethod"] = "InvalidReceiveMethod";
RejectReasonTag["InvalidModuleReference"] = "InvalidModuleReference";
RejectReasonTag["InvalidContractAddress"] = "InvalidContractAddress";
RejectReasonTag["RuntimeFailure"] = "RuntimeFailure";
RejectReasonTag["AmountTooLarge"] = "AmountTooLarge";
RejectReasonTag["SerializationFailure"] = "SerializationFailure";
RejectReasonTag["OutOfEnergy"] = "OutOfEnergy";
RejectReasonTag["RejectedInit"] = "RejectedInit";
RejectReasonTag["RejectedReceive"] = "RejectedReceive";
RejectReasonTag["NonExistentRewardAccount"] = "NonExistentRewardAccount";
RejectReasonTag["InvalidProof"] = "InvalidProof";
RejectReasonTag["AlreadyABaker"] = "AlreadyABaker";
RejectReasonTag["NotABaker"] = "NotABaker";
RejectReasonTag["InsufficientBalanceForBakerStake"] = "InsufficientBalanceForBakerStake";
RejectReasonTag["StakeUnderMinimumThresholdForBaking"] = "StakeUnderMinimumThresholdForBaking";
RejectReasonTag["BakerInCooldown"] = "BakerInCooldown";
RejectReasonTag["DuplicateAggregationKey"] = "DuplicateAggregationKey";
RejectReasonTag["NonExistentCredentialID"] = "NonExistentCredentialID";
RejectReasonTag["KeyIndexAlreadyInUse"] = "KeyIndexAlreadyInUse";
RejectReasonTag["InvalidAccountThreshold"] = "InvalidAccountThreshold";
RejectReasonTag["InvalidCredentialKeySignThreshold"] = "InvalidCredentialKeySignThreshold";
RejectReasonTag["InvalidEncryptedAmountTransferProof"] = "InvalidEncryptedAmountTransferProof";
RejectReasonTag["InvalidTransferToPublicProof"] = "InvalidTransferToPublicProof";
RejectReasonTag["EncryptedAmountSelfTransfer"] = "EncryptedAmountSelfTransfer";
RejectReasonTag["InvalidIndexOnEncryptedTransfer"] = "InvalidIndexOnEncryptedTransfer";
RejectReasonTag["ZeroScheduledAmount"] = "ZeroScheduledAmount";
RejectReasonTag["NonIncreasingSchedule"] = "NonIncreasingSchedule";
RejectReasonTag["FirstScheduledReleaseExpired"] = "FirstScheduledReleaseExpired";
RejectReasonTag["ScheduledSelfTransfer"] = "ScheduledSelfTransfer";
RejectReasonTag["InvalidCredentials"] = "InvalidCredentials";
RejectReasonTag["DuplicateCredIDs"] = "DuplicateCredIDs";
RejectReasonTag["NonExistentCredIDs"] = "NonExistentCredIDs";
RejectReasonTag["RemoveFirstCredential"] = "RemoveFirstCredential";
RejectReasonTag["CredentialHolderDidNotSign"] = "CredentialHolderDidNotSign";
RejectReasonTag["NotAllowedMultipleCredentials"] = "NotAllowedMultipleCredentials";
RejectReasonTag["NotAllowedToReceiveEncrypted"] = "NotAllowedToReceiveEncrypted";
RejectReasonTag["NotAllowedToHandleEncrypted"] = "NotAllowedToHandleEncrypted";
})(RejectReasonTag = exports.RejectReasonTag || (exports.RejectReasonTag = {}));
function instanceOfTransferWithMemoTransactionSummary(object) {
return (object.type !== undefined && object.type.contents === 'transferWithMemo');
}
exports.instanceOfTransferWithMemoTransactionSummary = instanceOfTransferWithMemoTransactionSummary;
var BlockItemKind;

@@ -56,2 +111,5 @@ (function (BlockItemKind) {

AccountTransactionType[AccountTransactionType["RegisterData"] = 21] = "RegisterData";
AccountTransactionType[AccountTransactionType["SimpleTransferWithMemo"] = 22] = "SimpleTransferWithMemo";
AccountTransactionType[AccountTransactionType["EncryptedTransferWithMemo"] = 23] = "EncryptedTransferWithMemo";
AccountTransactionType[AccountTransactionType["TransferWithScheduleWithMemo"] = 24] = "TransferWithScheduleWithMemo";
})(AccountTransactionType = exports.AccountTransactionType || (exports.AccountTransactionType = {}));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secondsSinceEpoch = exports.countSignatures = exports.isValidHash = exports.isHex = exports.buildJsonResponseReviver = exports.unwrapJsonResponse = exports.unwrapBoolResponse = exports.intToStringTransformer = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const concordium_p2p_rpc_pb_1 = require("../grpc/concordium_p2p_rpc_pb");

@@ -72,3 +71,16 @@ /**

else if (bigIntPropertyKeys.includes(key)) {
return BigInt(value);
// Handle the special case where amount is a scheduled amount,
// which has an array structure.
if (key === 'amount' && Array.isArray(value)) {
const result = [];
for (const entry of value) {
const schedule = {
timestamp: new Date(entry[0]),
amount: BigInt(entry[1]),
};
result.push(schedule);
}
return result;
}
return value === null ? value : BigInt(value);
}

@@ -75,0 +87,0 @@ return value;

{
"name": "@concordium/node-sdk",
"version": "0.1.9",
"version": "0.2.4",
"description": "Helpers for interacting with the Concordium node",

@@ -5,0 +5,0 @@ "repository": {

@@ -32,8 +32,5 @@ # concordium-node-sdk-js

## Send a simple transfer
The following examples demonstrates how a simple transfer can be created and sent.
## Create a simple transfer
The following example demonstrates how a simple transfer can be created.
```js
import * as ed from "noble-ed25519";
// Create the transaction
const header: AccountTransactionHeader = {

@@ -44,3 +41,3 @@ expiry: new TransactionExpiry(new Date(Date.now() + 3600000)),

};
const simpleTransfer: SimpleTransfer = {
const simpleTransfer: SimpleTransferPayload = {
amount: new GtuAmount(100n),

@@ -54,7 +51,38 @@ toAddress: new AccountAddress("4hXCdgNTxgM7LNm8nFJEfjDhEcyjjqQnPSRyBS9QgmHKQVxKRf"),

};
```
## Create a simple transfer with a memo
The following example demonstrates how a simple transfer with a memo can be created.
```js
const header: AccountTransactionHeader = {
expiry: new TransactionExpiry(new Date(Date.now() + 3600000)),
nonce: 1n, // the next nonce for this account, can be found using getNextAccountNonce
sender: new AccountAddress("4ZJBYQbVp3zVZyjCXfZAAYBVkJMyVj8UKUNj9ox5YqTCBdBq2M"),
};
const simpleTransferWithMemo: SimpleTransferWithMemoPayload = {
amount: new GtuAmount(100n),
toAddress: new AccountAddress("4hXCdgNTxgM7LNm8nFJEfjDhEcyjjqQnPSRyBS9QgmHKQVxKRf"),
memo: new Memo(Buffer.from('6B68656C6C6F20776F726C64', 'hex')),
};
const simpleTransferWithMemoAccountTransaction: AccountTransaction = {
header: header,
payload: simpleTransferWithMemo,
type: AccountTransactionType.SimpleTransferWithMemo,
};
```
## Send Account Transaction
The following example demonstrates how to send any account transaction.
See the previous sections for how to create an account transaction.
```js
import * as ed from "noble-ed25519";
let accountTransaction: AccountTransaction;
// Create the transaction
// ...
// Sign the transaction, the following is just an example, and any method for signing
// with the key can be employed.
const signingKey = "ce432f6bba0d47caec1f45739331dc354b6d749fdb8ab7c2b7f6cb24db39ca0c";
const hashToSign = getAccountTransactionSignDigest(simpleTransferAccountTransaction, sha256);
const hashToSign = getAccountTransactionSignDigest(accountTransaction, sha256);
const signature = Buffer.from(await ed.sign(hashToSign, signingKey)).toString("hex");

@@ -73,3 +101,3 @@

// Send the transaction to the node.
const success = await client.sendAccountTransaction(simpleTransferAccountTransaction, signatures);
const success = await client.sendAccountTransaction(accountTransaction, signatures);
if (success) {

@@ -84,6 +112,7 @@ // The node accepted the transaction. This does not ensure that the transaction

// as it will take some time for the transaction to be processed.
const transactionHash = getAccountTransactionHash(simpleTransferAccountTransaction, signatures, sha256);
const transactionHash = getAccountTransactionHash(accountTransaction, signatures, sha256);
const transactionStatus = await client.getTransactionStatus(transactionHash);
```
## getAccountInfo

@@ -186,2 +215,25 @@ Retrieves information about an account. If no account exists with the provided address, then the node

## Check block for transfers with memo
The following example demonstrates how to check and parse a block
for transfers with a memo.
```js
const blockHash = "b49bb1c06c697b7d6539c987082c5a0dc6d86d91208874517ab17da752472edf";
const blockSummary = await client.getBlockSummary(blockHash);
const transactionSummaries = blockSummary.transactionSummaries;
for (const transactionSummary of transactionSummaries) {
if (transactionSummary.result.outcome === 'success') {
if (instanceOfTransferWithMemoTransactionSummary(transactionSummary)) {
const [transferredEvent, memoEvent] = transactionSummary.result.events;
const toAddress = transferredEvent.to.address;
const amount = transferredEvent.amount;
const memo = memoEvent.memo;
// Apply business logic to toAddress, amount and memo...
}
}
}
```
# Build

@@ -195,2 +247,10 @@

## Publishing a release
Before publishing a new release it is essential that it has been built first. So make sure that
you have just built the up-to-date code you want to publish. To publish the release run
```
yarn publish
```
and step through the steps precented to you.
## Updating the gRPC files

@@ -197,0 +257,0 @@ If the external dependency concordium-grpc-api has been updated (or this is your first time building the project),