Swisstronik Docs
  • 🇨🇭About Swisstronik
    • What is Swisstronik?
    • Swisstronik vs Ethereum
    • Useful links
  • 🌐General
    • Intel SGX
    • Governance
      • On-Chain Proposal
      • Formatting a Proposal
      • Submitting a Proposal
      • Governable Parameters
    • Community Pool
    • Accounts
    • Transactions
    • Gas and Fees
    • Coin & Tokens
  • ⚒️Development
    • Endpoints
    • Connect wallets
      • MetaMask (EVM) - Manual
      • Keplr (Cosmos)
      • Testnet Metamask (EVM) - Chainlist
      • Testnet MetaMask (EVM) - Manual
      • Testnet Keplr (Cosmos)
    • Get test coins
    • SwisstronikJS SDK
      • SwisstronikJS Functions
      • Swisstronik & Ethereum transactions
      • Transaction - code sample
      • Swisstronik & Ethereum calls
      • Call - code sample
    • Swisstronik CLI
      • Installation
      • Configuration
      • Key management
      • Queries
      • Sending SWTR
      • For SDI Issuers
    • Guides
      • Contract deployment - Hardhat
        • 1. Setting up the Hardhat environment
        • 2. Configure hardhat.config.js
        • 3. Write and compile the smart contract
        • 4. Deploy the smart contract
        • 5. Interact with the contract - Transaction
        • 6. Interact with the contract - Call
      • Contract deployment - Remix IDE
      • Deployment & Interaction PERC-20
        • ERC-20 & PERC-20
        • Sample PERC20 contract
        • Deployment & Interaction with contract
        • How to use encryption
      • Contract verification
      • SDI for dapp developers
    • Local testnet
    • Web3JS, Ethers, Viem and other third-party libraries
  • 🖥️Node setup
    • Setup SGX
      • Supported Hardware
      • Setup Intel SGX
    • Setup node
      • Mainnet
        • v1.0.1 Upgrade
      • Testnet
        • Install from .deb package
        • Configure node
        • Upgrade your testnet node
          • Swisstronik v3 Testnet
          • Swisstronik v4 Testnet
          • Swisstronik v5 Testnet
          • Swisstronik v5.1 Testnet
          • Swisstronik v6 Testnet
          • Swisstronik v7 Testnet
          • Swisstronik v8 Testnet
        • Seed Node
        • Live Peers
        • Genesis Mirror Download
    • CLI Cheatsheet
  • 🤝Delegators
    • What is a delegator?
    • Delegator Guide (CLI)
    • Delegators Security
Powered by GitBook
On this page
  1. Development
  2. Guides
  3. Deployment & Interaction PERC-20

Deployment & Interaction with contract

PreviousSample PERC20 contractNextHow to use encryption

Last updated 1 year ago

(Source code you can find here: )

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:

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

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:

npx hardhat run --network $YOUR_NETWORK $PATH_TO_YOUR_SCRIPT

Interact with contract

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

Transaction / Call without data field

Transaction / Call with data field

✅

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:

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
https://hardhat.org/hardhat-runner/docs/config
https://github.com/SigmaGmbH/swisstronik-tutorials/blob/main/PERC20_interaction/test/test.js
🚫
🚫