This library can be used to create, sign and serialize transactions meant to be sent to the CyberChain blockchain.
This is a fork of the tx package, from EthereumJS.
To obtain the latest version, simply require the project using npm:
npm install @cyberchain/txSee the following code snipped for an example on how create and sign a transaction.
import {
FeeMarketEIP1559TxData,
FeeMarketEIP1559Transaction,
SignKey,
} from "@cyberchain/tx";
import { Common } from "@ethereumjs/common";
import { Address } from '@ethereumjs/util';
const chainId = BigInt(1337);
function buildTransaction() {
const customCommon = Common.custom(
{
name: "my-network",
networkId: chainId,
chainId: chainId,
},
{
baseChain: "mainnet",
hardfork: "london",
}
);
const txData: FeeMarketEIP1559TxData = {
to: "0x1111111111111111111111111111111111111111",
data: "0x",
value: BigInt(0),
nonce: 1,
gasLimit: BigInt(6000000),
chainId: chainId,
maxFeePerGas: 0,
maxPriorityFeePerGas: 0,
};
// Create transaction
let tx = new FeeMarketEIP1559Transaction(txData, { common: customCommon });
// Sign transaction
const signKey: SignKey = {
type: "ec-dsa",
key: Buffer.from("1111111111111111111111111111111111111111111111111111111111111111", "hex")
};
const complementaryAddress = new Address(Buffer.from("2222222222222222222222222222222222222222", 'hex'));
tx = tx.sign(signKey, complementaryAddress);
// Serialize transaction
const serializedTx = tx.serialize();
return serializedTx;
}