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. */constsendShieldedTransaction=async (signer, destination, data, value) => {// Get the RPC link from the network configurationconstrpclink=hre.network.config.url;// Encrypt transaction dataconst [encryptedData] =awaitencryptDataField(rpclink, data);// Construct and sign transaction with encrypted datareturnawaitsigner.sendTransaction({ from:signer.address, to: destination, data: encryptedData, value, });};
Write the main script to use sendShieldedTransaction function
asyncfunctionmain() {// Address of the deployed contractconstcontractAddress="0xf84Df872D385997aBc28E3f07A2E3cd707c9698a";// Get the signer (your account)const [signer] =awaithre.ethers.getSigners();// Construct a contract instanceconstcontractFactory=awaithre.ethers.getContractFactory("Swisstronik");constcontract=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);
awaitsetMessageTx.wait();//It should return a TransactionResponse objectconsole.log("Transaction Receipt: ", setMessageTx);}