Submit a transaction to a Concordium node#

The following sections document the requirements for creating an account transaction, signing it, and sending it to a Concordium node.

Construct and sign an account transaction#

This example constructs and signs a simple transfer, which is an account transaction that moves an amount of CCD from one account to another. For other transaction types, the steps are similar, but the exact fields that must be provided for the payload will be different. Note that Concordium as a whole supports multi-signature transactions, but for the purpose of this example it will demonstrate how to sign for an account with a single credential that has a single key.

Note that when the transaction has been signed anyone with the signature and the transaction will be able to send it to a Concordium node. Therefore it is very important that a wallet requests user approval before utilizing their signing keys.

import {
    AccountAddress,
    AccountTransaction,
    AccountTransactionHeader,
    buildBasicAccountSigner,
    CcdAmount,
    ConcordiumGRPCWebClient,
    ConcordiumHdWallet,
    getAccountAddress,
    signTransaction,
    SimpleTransferPayload,
    TransactionExpiry,
} from '@concordium/web-sdk';

const seedPhrase = 'fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position';
const network = 'Testnet'; // Or Mainnet, if working on mainnet.
const wallet = ConcordiumHdWallet.fromSeedPhrase(seedPhrase, network);

const client = new ConcordiumGRPCWebClient(nodeAddress, nodePort);
const cryptographicParameters = await client.getCryptographicParameters();

const credId = wallet.getCredentialId(identityProviderIndex, identityIndex, credNumber, cryptographicParameters);
const sender = getAccountAddress(credId);

const toAddress = AccountAddress.fromBase58('4QkqdUnrjShrUrHpE96odLM6J77nWzEryifzqNnwNk4FYNge8a');

const amount = CcdAmount.fromMicroCcd(5000000);

const payload: SimpleTransferPayload = {
    amount,
    toAddress
};

const expiry = TransactionExpiry.fromDate(new Date(Date.now() + 360000));

const nonce = (await client.getNextAccountNonce(sender)).nonce;

const header: AccountTransactionHeader = {
    expiry:
    nonce,
    sender,
};

const transaction: AccountTransaction = {
    type: AccountTransactionType.Transfer,
    payload,
    header,
};

const signingKey = wallet.getAccountSigningKey(identityProviderIndex, identityIndex, credNumber);
const signer = buildBasicAccountSigner(signingKey.toString('hex'));

const signature = await signTransaction(accountTransaction, signer);

Send an account transaction to a Concordium node#

Finally, when the transaction has been constructed and signed, it is ready to be sent to a Concordium node. The output of the function sending a transaction to a Concordium node is the transaction hash. The transaction hash can then be used to monitor the status of the submitted transaction.

import {
    ConcordiumGRPCWebClient,
} from '@concordium/web-sdk';

const client = new ConcordiumGRPCWebClient(nodeAddress, nodePort);
const transactionHash = await client.sendAccountTransaction(accountTransaction, signature);
Was this article helpful?
Legal information