Let's use sendShieldedTransaction to send a call/query to the blockchain
/**
* 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 network configuration
const rpclink = hre.network.config.url;
// Encrypt transaction data
const [encryptedData] = await encryptDataField(rpclink, data);
// Construct and sign transaction with encrypted data
return await signer.sendTransaction({
from: signer.address,
to: destination,
data: encryptedData,
value,
});
};
Write the main script to use sendShieldedTransaction function
async function main() {
// Address of the deployed contract
const contractAddress = "0xf84Df872D385997aBc28E3f07A2E3cd707c9698a";
// Get the signer (your account)
const [signer] = await hre.ethers.getSigners();
// Construct a contract instance
const contractFactory = await hre.ethers.getContractFactory("Swisstronik");
const contract = contractFactory.attach(contractAddress);
// Send a shielded transaction to set a message in the contract
const setMessageTx = await sendShieldedTransaction(signer, contractAddress, contract.interface.encodeFunctionData("setMessage", ["Hello Swisstronik!!"]), 0);
await setMessageTx.wait();
//It should return a TransactionResponse object
console.log("Transaction Receipt: ", setMessageTx);
}