Transaction - code sample
Sending Transactions in Swisstronik
const hre = require("hardhat");
const { encryptDataField } = require("@swisstronik/utils");const hre = require("hardhat");
const { encryptDataField } = require("@swisstronik/utils");
/**
* Send a shielded transaction to the Swisstronik blockchain.
*
* @param {object} signer - The signer object for sending the transaction.
* @param {string} destination - The address of the contract to interact with.
* @param {string} data - Encoded data for the transaction.
* @param {number} value - Amount of value to send with the transaction.
*
* @returns {Promise} - The transaction object.
*/
const sendShieldedTransaction = async (signer, destination, data, value) => {
// Get the RPC link from the Hardhat network configuration
const rpcLink = hre.network.config.url;
// Encrypt transaction data
const [encryptedData] = await encryptDataField(rpcLink, data);
// Construct and sign the transaction with encrypted data
return await signer.sendTransaction({
from: signer.address,
to: destination,
data: encryptedData,
value,
});
};Last updated