Sign a transaction

In this tutorial, you will learn how to sign a transaction in FastSet.

Signing a transaction involves several steps:

1. Construct the Transaction data type and serialize it.

Recall a Transaction data type contains several fields. We construct each individually first, and we serialize the structure at the end.

In order to perform a transaction, we need a sender and a receiver and their addresses.

In FastSet, the public keys of the accounts are also their addresses. The private keys are, as their name says, private and they should be kept as such.

Let's assume the public address of the sender is senderPublicKey and the public address of the receiver is recipientPublicKey .

In FastSet we distinguish between addresses native to FastSet and addresses owned by external entities such as blockchains. In this example, we assume the recipient is native.

The address of the recipient is constructed from their public key:

const Address = { FastSet: recipientPublicKey };

In FastSet, only the order of transactions originating from the same account is enforced. For this, every transaction carries a nonce denoting the transaction number.

The nonce on FastSet is similar to Ethereum's nonce.

const Nonce = bcs.u64();

FastSet is more than settling payment transactions. In FastSet, you can settle what we call claims, independently verifiable statements. Claims include, but are not limited to voting, verifiable computing, or auctions. As such, the data type for claims ClaimType comes in different variants. In this example, we focus on a token transfer:

const ClaimType = bcs.enum("ClaimType", {
    TokenTransfer: TokenTransfer,
});
const Transaction = bcs.struct("Transaction", {
    sender: senderPublicKey,
    recipient: {FastSet: recipientPublicKey},
    nonce: Nonce,
    timestamp_nanos: bcs.u128(),
    claim: ClaimType,
});

2. Sign the transaction

Before a transaction is sent, it has to be signed by the sender.

Last updated

Was this helpful?