# Interact with the contract-Transaction

{% hint style="info" %}
Make sure you have installed SwisstronikJS by running `npm i @swisstronik/swisstronik.js`
{% endhint %}

1. Within the scripts folder, create a file called `setMessage.js`

<figure><img src="https://934886813-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjQ2LiNEFvdY09gfwcysG%2Fuploads%2F2Gx6Bi8RANd5W8bB5nNI%2Fimage.png?alt=media&#x26;token=03f54188-3241-44fe-acf8-523317aa43ab" alt=""><figcaption></figcaption></figure>

2. Let's write our `setMessage.js` script

* Import hardhat and swisstronikJS functions

```
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/swisstronik.js");
```

* 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);
}
```

* Add this by hardhat default

```
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

{% hint style="success" %}
The final `setMessage.js` script should look like this:
{% endhint %}

```
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/swisstronik.js");

const sendShieldedTransaction = async (signer, destination, data, value) => {
  const rpclink = hre.network.config.url;
  const [encryptedData] = await encryptDataField(rpclink, data);
  return await signer.sendTransaction({
    from: signer.address,
    to: destination,
    data: encryptedData,
    value,
  });
};

async function main() {
  const contractAddress = "0xf84Df872D385997aBc28E3f07A2E3cd707c9698a";
  const [signer] = await hre.ethers.getSigners();
  const contractFactory = await hre.ethers.getContractFactory("Swisstronik");
  const contract = contractFactory.attach(contractAddress);
  const functionName = "setMessage";
  const messageToSet = "Hello Swisstronik!!";
  const setMessageTx = await sendShieldedTransaction(signer, contractAddress, contract.interface.encodeFunctionData(functionName, [messageToSet]), 0);
  await setMessageTx.wait();
  console.log("Transaction Receipt: ", setMessageTx);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

3. Execute the following command in your terminal to run the script using the Swisstronik network

   `npx hardhat run scripts/setMessage.js --network swisstronik`
4. Upon successful execution, your terminal should display `Transaction Receipt: TransactionResponse {...}` , now it's time to retrieve this message🎉
