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

Sample PERC20 contract

PreviousERC-20 & PERC-20NextDeployment & Interaction with contract

Last updated 1 year ago

There is a sample PERC20 (Private ERC20) contract with disabled logs and signature check in the balanceOf function

Contract developers should avoid adding sensitive information to logs, such as transfer amounts, sender and recipient, etc. But you still can use them for some debugging or contract-wide events, for example, contract initialization.

Also, you should be careful with public view functions that can also leak some sensitive information, for example, user balance. In the example, we're using a msg.sender check to verify if the caller is the wallet owner. If this function was called from EOA (Externally Owned Account), EVM will try to recover msg.sender from provided signature within eth_call.

Code of that contract you can see below (full example you can find here: )

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "./PERC20.sol";

/**
 * @dev Sample implementation of the {PERC20} contract.
 */
contract PERC20Sample is PERC20 {
    constructor() PERC20("Sample PERC20", "pSWTR") {}

    /// @dev Wraps SWTR to PSWTR.
    receive() external payable {
        _mint(_msgSender(), msg.value);
    }

    /**
     * @dev Regular `balanceOf` function marked as internal, so we override it to extend visibility  
     */ 
    function balanceOf(address account) public view override returns (uint256) {
        // This function should be called by EOA using signed `eth_call` to make EVM able to
        // extract original sender of this request. In case of regular (non-signed) `eth_call`
        // msg.sender will be empty address (0x0000000000000000000000000000000000000000).
        require(msg.sender == account, "PERC20Sample: msg.sender != account");

        // If msg.sender is correct we return the balance
        return _balances[account];
    }

    /**
     * @dev Regular `allowance` function marked as internal, so we override it to extend visibility  
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        // This function should be called by EOA using signed `eth_call` to make EVM able to
        // extract original sender of this request. In case of regular (non-signed) `eth_call`
        // msg.sender will be empty address (0x0000000000000000000000000000000000000000)
        require(msg.sender == spender, "PERC20Sample: msg.sender != account");
        
        // If msg.sender is correct we return the allowance
        return _allowances[owner][spender];
    }
}
⚒️
https://github.com/SigmaGmbH/swisstronik-tutorials/blob/main/PERC20_interaction/contracts/PERC20Sample.sol