> For the complete documentation index, see [llms.txt](https://docs.logosnodos.online/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.logosnodos.online/solidity-compiler/hardhat/perc20-private-erc20-deploy-mint-and-transfer..md).

# PERC20 (Private ERC20) Deploy, Mint and Transfer.

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

1. Make an .env file for store your PK (Private Key) to access your wallet.
2. Ensure you have enough funds token to doing the task.
3. Make 3 file (deploy.js, mint.js and transfer.js) inside the script folder&#x20;
4. Open the `deploy.js` file and write our script

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

async function main() {
  const perc20 = await ethers.deployContract("PERC20Sample");
  await perc20.deployed();

  console.log(`PERC20 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;
});
```

5. And then let's write our `mint.js` script

```
// Import necessary modules from Hardhat and SwisstronikJS
const hre = require("hardhat");
const {
  encryptDataField,
  decryptNodeResponse,
} = require("@swisstronik/swisstronik.js");

// Function to send a shielded transaction using the provided signer, destination, data, and value
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,
  });
};

async function main() {
  // Address of the deployed contract
  const contractAddress = "0x2eEa4a8A9B7D8FE2b9d3A6e0e08708046d6bacfb";

  // Get the signer (your account)
  const [signer] = await hre.ethers.getSigners();

  // Create a contract instance
  const contractFactory = await hre.ethers.getContractFactory("PERC20Sample");
  const contract = contractFactory.attach(contractAddress);

  // Send a shielded transaction to mint 100 tokens in the contract
  const functionName = "mint";
  const mintToken = await sendShieldedTransaction(
    signer,
    contractAddress,
    contract.interface.encodeFunctionData(functionName),
    0
  );

  await mintToken.wait();

  // It should return a TransactionReceipt object
  console.log("Mint Transaction Hash: ", mintToken.hash);
}

// Using async/await pattern to handle errors properly
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
```

6. And the last write our `transfer.js` script

```
// Import necessary modules from Hardhat and SwisstronikJS
const hre = require("hardhat");
const {
  encryptDataField,
  decryptNodeResponse,
} = require("@swisstronik/swisstronik.js");

// Function to send a shielded transaction using the provided signer, destination, data, and value
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,
  });
};

async function main() {
  // your deployed contract
  const replace_contractAddress = "0x2eEa4a8A9B7D8FE2b9d3A6e0e08708046d6bacfb";

  const [signer] = await hre.ethers.getSigners();

  const replace_contractFactory = await hre.ethers.getContractFactory(
    "PERC20Sample"
  );
  const contract = replace_contractFactory.attach(replace_contractAddress);

  const replace_functionName = "transfer";
  const replace_functionArgs = ["0x16af037878a6cAce2Ea29d39A3757aC2F6F7aac1","1",];
  const transaction = await sendShieldedTransaction(
    signer,
    replace_contractAddress,
    contract.interface.encodeFunctionData(
      replace_functionName,
      replace_functionArgs
    ),
    0
  );

  await transaction.wait();

  console.log("Transfer Transaction Hash: ", transaction.hash);
}

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

4. Don't forget to compile the contract

```
npm run compile
```

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

```
npm run deploy
```

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

```
npm run mint
```

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

```
npm run transfer
```

Upon successful execution, your terminal should display the latest message you've defined in the contract 🎉
