# Deployment & Interaction with contract

(Source code you can find here: [https://github.com/SigmaGmbH/swisstronik-tutorials/blob/main/PERC20\_interaction](https://github.com/SigmaGmbH/swisstronik-tutorials/blob/main/PERC20_interaction/contracts/PERC20Sample.sol))

In this guide, we will use the PERC20 contract, which we have seen in the previous step. Also, we will use hardhat for example of deployment script. Since Swisstronik has almost the same JSON-RPC as Ethereum, you can use any library/tool you like

You can deploy the `PrivateSWTR` contract from the sample `hardhat-basic` project with a deployment script like this:

```javascript
const { ethers } = require("hardhat");

async function main() {
  const perc20 = await ethers.deployContract("PERC20Sample");
  await perc20.waitForDeployment();
  
  console.log(`PERC20Sample was deployed to ${perc20.address}`)
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

Before running this script, make sure to modify your `hardhat.config.js` file by adding the node address and your private key account. Here you can read more about the configuration of hardhat: <https://hardhat.org/hardhat-runner/docs/config>

```javascript
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config()

module.exports = {
  defaultNetwork: "swisstronik",
  solidity: "0.8.18",
  networks: {
    swisstronik: {
      // If you're using local testnet, replace `url` with local json-rpc address 
      url: "https://json-rpc.testnet.swisstronik.com/",
      accounts: [`0x` + `${process.env.PRIVATE_KEY}`],
    },
  },
};

```

Then you will be able to deploy your contract by running:&#x20;

```
npx hardhat run --network $YOUR_NETWORK $PATH_TO_YOUR_SCRIPT
```

### Interact with contract

You can see how we interact with PERC20 contract in tests for PERC20Sample. You can find it here: <https://github.com/SigmaGmbH/swisstronik-tutorials/blob/main/PERC20_interaction/test/test.js>

As you can see there, to interact with a deployed contract you need a few helper functions which will do encryption/decryption of query and encrypt transaction `data` field. Every method which contains `data` requires encryption, except contract deployment. In the table below you can find which methods require encrypted payload

| Type of interaction                     | Required encryption                      |
| --------------------------------------- | ---------------------------------------- |
| Contract deployment                     | [🚫](https://emojipedia.org/prohibited/) |
| Transaction / Call without `data` field | [🚫](https://emojipedia.org/prohibited/) |
| Transaction / Call with `data` field    | ✅                                        |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.swisstronik.com/swisstronik-docs/development/guides/deployment-and-interaction-perc-20/deployment-and-interaction-with-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
