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.
- 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>
- 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],
}
Clone the repository and install the dependecies.
$ npm install --save-dev
Compile the contracts
$ npx hardhat compile
Smart contracts can be deployed on the hardhat local network. It is an EVM-like emulated chain.
- Start a local node
$ npm install
$ npx hardhat node
- In another shell we can run the deployment script by specifying the local hardhat network
$ npx hardhat run --network localhost scripts/deploy.js
- To fund your addresses
$ npx hardhat --network localhost faucet <eth-address>
- Deploy the contracts
$ npx hardhat run --network iota-evm-testnet scripts/deploy.js
- Create a random passport
$ python3 ./scripts/create_passport.py
- Deploy the NFT and datatokens
$ node ./scripts/deploy_nft.js
- Transfer the datatokens to account2's address
$ node ./scripts/transfer_token.js
- Accumulate part of the datatokens to factory address
$ node ./scripts/accumulate_token.js
- Burn all accumulated datatokens to mint a new NFT
$ node ./scripts/burn_to_mint_nft.js
MetaMask installed and configured in your browser.
- 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
- 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
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.
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
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.
- 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//'
}
}
]
}
};
- Verify the SCs' code:
$ npx hardhat verify --network iota-evm-testnet <contract address> "<contract constructor Arg1>" "<contract constructor Arg2>"