Skip to content

Cybersecurity-LINKS/rmp-smart-contracts

Repository files navigation

Raw Material Passport Smart Contracts

This repository contains the implementation of the Smart Contracts for the Raw Material Passport (RMP), which are developed by the Cybersecurity Research Group at LINKS Foundation as part of the MASTERMINE project.

Prepare environment

  1. Create a .env file and where o save the private key of your wallet. The .env file should look like this:
#Account 1 keys => deployer account
PUBLIC_KEY=<PRIV KEY>
PRIVATE_KEY=<PUB KEY>

#Account 2 keys => to transfer the datatokens
PRIVATE_KEY_ACCOUNT2=<PRIV KEY>
PUBLIC_KEY_ACCOUNT2=<PUB KEY>

ADDRESS_FILE=./addresses/contractAddresses.json
NETWORK_URL= <RPC URL>
SC_DIR=<FOLDER PATH>
  1. In the hardhat.config.js specify the various networks to play around with different wallets
    'iota-evm-testnet': {
      url: 'https://json-rpc.evm.testnet.iotaledger.net',
      chainId: 1075,
      gas: 2100000, 
      gasPrice: 1000000000000,
      accounts: [process.env.PRIVATE_KEY],
    }

Requirements

  1. Solidity compiler (hardhat)
  2. npm

Clone the repository and install the dependecies.

$ npm install --save-dev

Compile the contracts

$ npx hardhat compile

Local Deployment

Smart contracts can be deployed on the hardhat local network. It is an EVM-like emulated chain.

  1. Start a local node
$ npm install
$ npx hardhat node
  1. In another shell we can run the deployment script by specifying the local hardhat network
$ npx hardhat run --network localhost scripts/deploy.js
  1. To fund your addresses
$ npx hardhat --network localhost faucet <eth-address>

Deploy the contracts and interact with them

  1. Deploy the contracts
$ npx hardhat run --network iota-evm-testnet scripts/deploy.js
  1. Create a random passport
$ python3 ./scripts/create_passport.py
  1. Deploy the NFT and datatokens
$ node ./scripts/deploy_nft.js
  1. Transfer the datatokens to account2's address
$ node ./scripts/transfer_token.js
  1. Accumulate part of the datatokens to factory address
$ node ./scripts/accumulate_token.js
  1. Burn all accumulated datatokens to mint a new NFT
$ node ./scripts/burn_to_mint_nft.js

Run a webpage to mint a RMP (NFT + Data Token)

Requirements

MetaMask installed and configured in your browser.

MetaMask Configuration

  • Download MetaMask from here
  • Agree to the terms of use, then click 'Create a new Wallet'
  • Click 'Create a new wallet'
  • Decide to agree or not to help improve MetaMask
  • Create a password
  • Click on 'Secure my wallet', to get the Secret Recovery Phrase (12 words), and save those words in a secure place. Be careful, these words are the key to access to your account do not share them
  • Confirm the Secret Recovery Phrase inserting the missing words in the form

Add a new Network to MetaMask

  • Open the wallet
  • Click on Ethereum Mainnet in the upper left corner
  • Click add a custom network in bottom
  • Complete in this way:
Network name: IOTA EVM Testnet
Default RPC URL: https://json-rpc.evm.testnet.iotaledger.net
Chain ID: 1075
Currency symbol: IOTA
Block explorer: https://explorer.evm.testnet.iotaledger.net/
  • Save, click again on Ethereum Mainnet in the upper left corner and select IOTA EVM Testnet

In this way all the transactions will be signed in the selected network

Usage

To deploy a webpage that allows minting a RMP, run these commands:

cd frontend_miner
npm install 
npm run dev

The terminal will tell the address of the webpage. On that page it is possible to insert the RMP data, the mint button in the bottom. At that point MetaMask will ask for your password (just the first time) and then will ask to confirm the transaction. A confirmation pop up will appear, download the file to not lose the NFT and the DT addresses. The NFT will be automatically added in MetaMask while you should need to add the DT. To add it, go to the token tab in MetaMask click the three dots and select 'Import Tokens' paste there the address shown in the confirmation pop up.

Test

A suite of tests has been written to test the correct functionality of the Smart Constracts. To run all the tests, execute this command:

npx hardhat test 

To run the tests for a specific component, run one of those commands:

npx hardhat test test/FixturesTest.js
npx hardhat test test/Factory.js
npx hardhat test test/NFT.js
npx hardhat test test/DataToken.js  

Verify the deployed smart contracts code

Verifying a contract means making its source code public, along with the compiler settings you used, which allows anyone to compile it and compare the generated bytecode with the one that is deployed on-chain.

  1. Modify the hardhat config by adding the etherscan information as follows:
    module.exports = {
        solidity: "0.8.18",
        settings: {
            ...
        },
        networks: {
            ...
        },
        etherscan: {
            apiKey: {
            'iota-evm-testnet': 'ABCDE12345ABCDE12345ABCDE123456789' 
            },
            customChains: [
            {
                network: 'iota-evm-testnet',
                chainId: 1071,
                urls: {
                apiURL: 'https://explorer.evm.testnet.iotaledger.net//api',
                browserURL: 'https://explorer.evm.testnet.iotaledger.net//'
                }
            }
            ]
        }
    };
  1. Verify the SCs' code:
$ npx hardhat verify --network iota-evm-testnet <contract address> "<contract constructor Arg1>" "<contract constructor Arg2>"

About

Raw Material Passport Smart Contracts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •