Call - code sample
Making Calls in Swisstronik
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");
/**
* Make a shielded query/call on the Swisstronik blockchain.
*
* @param {object} provider - The provider object for making the call.
* @param {string} destination - The contract address to call.
* @param {string} data - Encoded data for the function call.
*
* @returns {Uint8Array} - Encrypted response from the blockchain.
*/
const sendShieldedQuery = async (provider, destination, data) => {
// Obtain the RPC link from the network configuration
const rpcLink = hre.network.config.url;
// Encrypt the call data using SwisstronikJS's encryption function
const [encryptedData, usedEncryptionKey] = await encryptDataField(rpcLink, data);
// Execute the query/call using the provider
const response = await provider.call({
to: destination,
data: encryptedData,
});
// Decrypt the response using SwisstronikJS's decryption function
return await decryptNodeResponse(rpcLink, response, usedEncryptionKey);
};Last updated