The code to execute a stake transaction on the Takamaka blockchain

27.02.23

A “stake” on the blockchain in general refers to the amount of cryptocurrency that a person holds and is willing to commit as collateral in order to participate in the consensus process of a specific network.

The term is most commonly used in the context of proof-of-stake (PoS) blockchain systems, where individuals can stake their coins to validate transactions and secure the network, rather than using computer power to solve complex mathematical puzzles (as in proof-of-work systems).

The more coins a person stakes, the higher their chances of being selected to validate a block of transactions and receive a reward.

The Code

First, you need to know that the code has been written in Java with the purpose of creating and executing a blockchain transaction. As explained in the introduction, the transaction involves a stake, which refers to the amount of cryptocurrency a person owns and is willing to pledge as collateral in order to participate in the consensus process of a specific blockchain network.

The code, which can be read at this link [https://github.com/takamaka-dev/takamaka-core-wallet-examples/blob/master/README.md], imports various classes from the takamaka package to enable the creation of a wallet, generation of a public key, and execution of a transaction. It also utilizes various utilities such as TkmSignUtilsTkmTK, and TransactionFeeCalculator.

In this specific case, the code is an example of how to execute a staking transaction on the Takamaka blockchain and includes the import of various classes and libraries to create a TransactionBox object, containing a stake transaction, to be sent to the blockchain. The stake transaction is then signed with a private key using the TkmSignUtils class, and its cost is calculated using the TransactionFeeCalculator class.

Finally, the TransactionBox object is sent to the blockchain through the TkmTK class.

package io.takamaka.takamaka.core.wallet.examples;

import io.takamaka.takamaka.core.wallet.examples.support.ProjectHelper;
import io.takamaka.wallet.InstanceWalletKeyStoreBCED25519;
import io.takamaka.wallet.InstanceWalletKeystoreInterface;
import io.takamaka.wallet.beans.FeeBean;
import io.takamaka.wallet.beans.InternalTransactionBean;
import io.takamaka.wallet.beans.TransactionBean;
import io.takamaka.wallet.beans.TransactionBox;
import io.takamaka.wallet.utils.BuilderITB;
import io.takamaka.wallet.utils.TkmSignUtils;
import io.takamaka.wallet.utils.TkmTK;
import io.takamaka.wallet.utils.TkmTextUtils;
import io.takamaka.wallet.utils.TkmWallet;
import io.takamaka.wallet.utils.TransactionFeeCalculator;
import java.math.BigInteger;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;

/**
*@author Giovanni Antino giovanni.antino@takamaka.io
*/
@Slf4j
public class SubmitStake {

The first part defines constants containing the names and passwords of the source and destination wallets, transaction parameters such as the amount of cryptocurrency to be transferred (in this case, 200 TKG), the transaction fee, and the transaction inclusion time.

log.info(“The minimum stake accepted from takamaka blockchain is “+ “200 TKG”);

final BigInteger twoHundredTKGValue = TkmTK.unitTK(200);
log.info(“200 TKG value in nano TKG “ + twoHundredTKGValue.toString());

The transaction is then executed using the TransactionBean class, which represents a tx on the blockchain. BuilderITB is a utility class that is used to create the transaction object, which is then signed, using the private key of the source wallet with the TkmSignUtils class.

InternalTransactionBean stakeITB = BuilderITB.stake(publicKeySource,publicKeyDestination,twoHundredTKGValue, “test stake”, transactionInclusionTime

….

Finally, the transaction is sent to the blockchain using the TkmWallet class.

TransactionBox stakeTbox = TkmWallet.verifyTransactionIntegrity( stakeTransactionJson); log.info(“the transaction is valid?: “ + stakeTbox.isValid());

 

CONCLUSIONS

The code uses various Java libraries such as Lombok and Takamaka Core Wallet, and employs different classes and methods such as InstanceWalletKeyStoreBCED25519, TkmTK, and TkmWallet.

To use this code, you need to have a Java development environment and all the required libraries, and you also need to provide the name of the wallets and the passwords for both the sender and the receiver of the transaction.

In general, the code allows for the creation and execution of a stake transaction on the Takamaka blockchain. For a more detailed explanation, please refer to the comments within the code itself.

You can find the code at the link- https://github.com/takamaka-dev/takamaka-core-wallet-examples/blob/master/src/main/java/io/takamaka/takamaka/core/wallet/examples/SubmitStake.java

Please visit

https://www.takamaka.io
https://github.com/takamaka-dev