Create Transactions

Prerequisites

  • The private key to the account with both testnet KAS on Layer 1 and bridged KAS on Layer 2.

Step1

Sign an L2 transaction using your private key. Kasplex L2 supports both Legacy Transactions and EIP-1559 transactions.

	tx := types.NewTx(&types.LegacyTx{
		Nonce:    nonce,
		To:       to,
		Value:    amount,
		Gas:      gasLimit,
		GasPrice: gasPrice,
		Data:     txdata,
	})
	signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
	vmData := signedTx.MarshalJSON()

Step2

To ensure the Kasplex L2 engine correctly parses L1 transactions, a fixed identifier 'kasplex' and a transaction type description must be added to the transaction.


	tx.Payload = []byte("kasplex")
	if marshalJSON {               //version 0 JSON
		tx.Payload = append(tx.Payload, 0x0)
	} else { //version 1 Binary
		tx.Payload = append(tx.Payload, 0x1)
	}
	tx.Payload = append(tx.Payload, vmData...)

Kasplex currently supports four type descriptions:

Type
Description

0x00

Json

0x01

Binary

0x80

zlib compressed Json

0x81

zlib compressed Binary

Read Deploy Contract chapter to understand why zlib compression is needed for data.

Step3

Check Transaction Receipt

curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0x255077c91162d2add8378905e62d7cabfa082061d84c10acc0a360d7b5dbf8c3"],"id":167012}' \
https://rpc.kasplextest.xyz

Last updated