UNPKG

@skalenetwork/libte-ts

Version:
39 lines (33 loc) 1.3 kB
const { encryptTransaction } = require('./main.js'); const ethers = require('ethers'); async function runSample() { // Example transaction data const txData = "1427693245b6ca220a4cdce7deca82240462e99222acbb65563079c69cc0120"; // Create a transaction object using ethers const ethersTransaction = new ethers.Transaction({ to: "0x1234567890abcdef1234567890abcdef12345678", value: ethers.parseEther("0.1"), gasLimit: 21000, gasPrice: ethers.parseUnits("50", "gwei"), data: txData, }); // Create a regular transaction object const transaction = { to: "0x1234567890abcdef1234567890abcdef12345678", value: BigInt(100000000000000000), gas: 21000, gasPrice: BigInt(50000000000), data: txData, }; try { // Encrypt the ethers transaction const encryptedEthersTx = await encryptTransaction(ethersTransaction); console.log("Encrypted Ethers Transaction:", encryptedEthersTx); // Encrypt the regular transaction const encryptedViemTx = await encryptTransaction(transaction); console.log("Encrypted Viem Transaction:", encryptedViemTx); } catch (error) { console.error("Failed to encrypt transaction:", error); } } runSample();