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. SwisstronikJS SDK

Swisstronik & Ethereum calls

Calls in the blockchain context are read-only interactions with the blockchain, retrieving information from the blockchain without altering, deleting, or adding data.

Ethereum Calls

We can use ethers.js to execute calls to the Ethereum blockchain. specifically for smart contracts, we can use provider.call({to, data}) to retrieve values from smart contracts

provider.call({
  to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
  // Function selector for `function getMessage(uint256)` + encoded argument `1`
  data: "0xa5f3c4f600000000000000000000000000000000000000000000000000000000000000001"
});

In this code example, the function call is made to the to smart contract address, executing the view returns function getMessage(uint256) while providing the argument 1. This process will return a message from the smart contract.

Swisstronik Calls

For Swisstronik calls, we need to make sure the data field of the call is encrypted using SwisstronikJS.

provider.call({
  to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
  //The `data` field must be an encrypted value, otherwise, the call will not work
  data: "0xf53a7d4fcf3116b8476ac3f986542794f0df2516070c555580ae29049c0ec91b8a2d82d2bf06694fea0c485fa48cb34b596a9f496a19f2ecb3c1da0540544cffb03f1dee14d7887fea1de6d982a46edfaab773"
});

This example shows that when making Swisstronik calls, the data field needs to be filled with an encrypted value using SwisstronikJS. Otherwise, the call won't work. Let's now explore how to encrypt this data for successful calls on the Swisstronik blockchain.

PreviousTransaction - code sampleNextCall - code sample

Last updated 1 year ago

⚒️