π¨π SwissTronik Mint 100 ERC-20 Tokens
3-2-1 GO !
cd $HOME
Crate A Directory :
mkdir Swissmint
Enter The Directory :
cd Swissmint
sudo apt-get remove -y nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash && export NVM_DIR="/usr/local/share/nvm"; [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"; [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"; source ~/.bashrc; nvm install --lts; nvm use --lts
npm install --save-dev hardhat
npm install --save-dev @nomicfoundation/hardhat-toolbox
npx hardhat
Enter
rm package.json
nano package.json
Copy - And Paste
{
"name": "hardhat-project",
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"hardhat": "^2.17.1"
},
"dependencies": {
"@openzeppelin/contracts": "^4.9.3",
"@swisstronik/utils": "^1.2.1"
}
}
CTRL X - CTRL Y - Enter. Saved.
rm hardhat.config.js
nano hardhat.config.js
Change "PASTE UR PRIVATE KEY WITHOUT 0X" Without 0x !
require("@nomicfoundation/hardhat-toolbox");
const PRIVATE_KEY = "PASTE UR PRIVATE KEY WITHOUT 0X";
module.exports = {
defaultNetwork: "swisstronik",
solidity: "0.8.19",
networks: {
swisstronik: {
url: "https://json-rpc.testnet.swisstronik.com/",
accounts: [`0x` + `${PRIVATE_KEY}`],
},
},
};
CTRL X - CTRL Y - Enter. Saved.
cd contracts
rm Lock.sol
nano Token.sol
Copy And Paste !
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract TestToken is ERC20 {
constructor()ERC20("RPCDOT","RPC"){}
function mint100tokens() public {
_mint(msg.sender,100*10**18);
}
function burn100tokens() public{
_burn(msg.sender,100*10**18);
}
}
CTRL X - CTRL Y - Enter. Saved.
npm install
npx hardhat compile
cd ..
mkdir scripts && cd scripts
nano deploy.js
Copy And Paste :
const hre = require("hardhat");
async function main() {
const contract = await hre.ethers.deployContract("TestToken");
await contract.waitForDeployment();
console.log(`deployed to ${contract.target}`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
CTRL X - CTRL Y - Enter.
cd ..
npx hardhat run scripts/deploy.js --network swisstronik
Copy the contract address !! And Save.
cd scripts
nano mint.js
Change : ENTER YOUR CONTRACT ADDRESS HERE
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");
const sendShieldedTransaction = async (signer, destination, data, value) => {
const rpcLink = hre.network.config.url;
const [encryptedData] = await encryptDataField(rpcLink, data);
return await signer.sendTransaction({
from: signer.address,
to: destination,
data: encryptedData,
value,
});
};
async function main() {
const contractAddress = "ENTER YOUR CONTRACT ADDRESS HERE";
const [signer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("TestToken");
const contract = contractFactory.attach(contractAddress);
const functionName = "mint100tokens";
const mint100TokensTx = await sendShieldedTransaction(
signer,
contractAddress,
contract.interface.encodeFunctionData(functionName),
0
);
await mint100TokensTx.wait();
console.log("Transaction Receipt: ", mint100TokensTx.hash);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
CTRL X - CTRL Y - Enter - Saved.
nano transfer.js
Change "PASTE YOUR CONTRACT ADDRESS HERE" :
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");
const sendShieldedTransaction = async (signer, destination, data, value) => {
const rpcLink = hre.network.config.url;
const [encryptedData] = await encryptDataField(rpcLink, data);
return await signer.sendTransaction({
from: signer.address,
to: destination,
data: encryptedData,
value,
});
};
async function main() {
const replace_contractAddress = "PASTE YOUR CONTRACT ADDRESS HERE";
const [signer] = await hre.ethers.getSigners();
const replace_contractFactory = await hre.ethers.getContractFactory("TestToken");
const contract = replace_contractFactory.attach(replace_contractAddress);
const replace_functionName = "transfer";
const replace_functionArgs = ["0x16af037878a6cAce2Ea29d39A3757aC2F6F7aac1", "1"];
const transaction = await sendShieldedTransaction(signer, replace_contractAddress, contract.interface.encodeFunctionData(replace_functionName, replace_functionArgs), 0);
await transaction.wait();
console.log("Transaction Response: https://explorer-evm.testnet.swisstronik.com/tx/" + transaction.hash);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
CTRL X - CTRL - Enter . Saved.
cd ..
npx hardhat run scripts/mint.js --network swisstronik
npx hardhat run scripts/transfer.js --network swisstronik
Save TX URL ! Paste it into the required field in the task.
Remove Private KEY !
nano hardhat.config.js
CTRL X - CTRL Y - Enter. Saved.
Last updated