4.12. Smart contract language
This chapter provides an overview of smart contract development using Solidity, a high-level, contract-oriented programming language for Ethereum. To enhance the process, we explore integrating Hardhat and Truffle.
Hardhat offers a powerful development environment with testing capabilities.
Truffle streamlines the workflow with tools for compilation, testing, and deployment.
Solidity's versatility enables smart contract development for various blockchain platforms, including Stargram. Leveraging these tools, developers can create robust and reliable smart contracts on platforms like Stargram Chain.
Hardhat: Deploy ERC20 Contract
Step 1. Enter
Step 2. Run npm install inside the folder
$ npm install
Step 3. Make a copy of .env.example to .env
$ cp .env.example .env
Step 4. Modify .env and fill ONE of the field
MNEMONIC=goose easy ivory ...
PRIVATE_KEY=XXXXXXX
Step 5. Review Migration Script at scripts/deploy-stars-token.js
async function main() {
const StarsToken = await hre.ethers.getContractFactory("StarsToken");
const starsToken = await StarsToken.deploy("Starsl Token", "CRT", "1000000000000000000000000");
await starsToken.deployed();
console.log("StarsToken deployed to:", starsToken.address);
}
Step 6. Endpoints setting
By default, the script will be using your local host "127.0.0.1" - If you are not running a localhost, you may leverage the public endpoint http://13.213.36.146:6868/ by making changes to networks in hardhat.config.js, for example:
networks: {
development: {
url: "http://localhost:8545",
accounts: getHDWallet(),
},
testnet: {
url: "http://13.213.36.146:6868",
accounts: getHDWallet(),
},
},
Step 7. Deploy Contract
npx hardhat run --network <your-network> scripts/deploy-stars-token.js
Step 8. Obtain Contract address from the console and input to Metamask
The correct balance will be shown on the Metamask page.
Truffle: Deploy ERC20 Contract
Step 1. Enter smart-contract-example/truffle folder
$ cd stars-smart-contract-example/truffle
Step 2. Run npm install inside the folder
$ npm install
Step 3. Make a copy of .env.example to .env
$ cp .env.example .env
Step 4. Modify .env and fill ONE of the fields
MNEMONIC=goose easy ivory ...
PRIVATE_KEY=XXXXXXX
Step 5. Review Migration Script at
migrations/2_deploy_stars_token.js
const StarsToken = artifacts.require("StarsToken");
module.exports = function (deployer) {
deployer.deploy(StarsToken, "Stars Token", "PT", "1000000000000000000000000");
};
Step 6. Endpoints setting
By default, the script will be using your local host "127.0.0.1" - If you are not running a localhost, you may leverage the public endpoint http://13.213.36.146:6868 by making changes to networks ins truffle-config.j, for example:
networks: {
development: {
provider: new HDWalletProvider(getHDWallet(), "http://127.0.0.1:8545"), // TODO
network_id: "*", // Any network (default: none)
},
testnet: {
provider: new HDWalletProvider(getHDWallet(), "http://13.213.36.146:6868/"), // TODO
network_id: "*",
skipDryRun: true
},
},
Step 7. Deploy Contract
truffle deployed --network <your-network>
Last updated