# 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.&#x20;

* Hardhat offers a powerful development environment with testing capabilities.
* Truffle streamlines the workflow with tools for compilation, testing, and deployment.&#x20;

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&#x20;

Step 2. Run <mark style="background-color:yellow;">npm install</mark> inside the folder

<mark style="background-color:yellow;">$ npm install</mark>

Step 3. Make a copy of <mark style="background-color:yellow;">.env.example to .env</mark>

<mark style="background-color:yellow;">$ cp .env.example .env</mark>

Step 4. Modify <mark style="background-color:yellow;">.env</mark> and fill ONE of the field

<mark style="background-color:yellow;">MNEMONIC=goose easy ivory ...</mark>

<mark style="background-color:yellow;">PRIVATE\_KEY=XXXXXXX</mark>

Step 5. Review Migration Script at <mark style="background-color:yellow;">scripts/deploy-stars-token.js</mark>

&#x20;<mark style="background-color:yellow;">async function main() {</mark>

&#x20;    <mark style="background-color:yellow;">const StarsToken = await hre.ethers.getContractFactory("StarsToken");</mark>

&#x20;    <mark style="background-color:yellow;">const starsToken = await StarsToken.deploy("Starsl Token", "CRT", "1000000000000000000000000");</mark>

&#x20;     <mark style="background-color:yellow;">await starsToken.deployed();</mark>

&#x20;     <mark style="background-color:yellow;">console.log("StarsToken deployed to:", starsToken.address);</mark>

&#x20;<mark style="background-color:yellow;">}</mark>

Step 6. Endpoints setting

By default, the script will be using your local host <mark style="background-color:yellow;">"127.0.0.1"</mark> - If you are not running a localhost, you may leverage the public endpoint <mark style="background-color:yellow;"><http://13.213.36.146:6868/></mark> by making changes to networks in <mark style="background-color:yellow;">hardhat.config.js</mark>, for example:

&#x20;<mark style="background-color:yellow;">networks: {</mark>

&#x20;  <mark style="background-color:yellow;">development: {</mark>

&#x20;    <mark style="background-color:yellow;">url: "<http://localhost:8545>",</mark>

&#x20;    <mark style="background-color:yellow;">accounts: getHDWallet(),</mark>

&#x20;   <mark style="background-color:yellow;">},</mark>

&#x20;  <mark style="background-color:yellow;">testnet: {</mark>

&#x20;    <mark style="background-color:yellow;">url: "<http://13.213.36.146:6868>",</mark>

&#x20;    <mark style="background-color:yellow;">accounts: getHDWallet(),</mark>

&#x20;  <mark style="background-color:yellow;">},</mark>

&#x20;<mark style="background-color:yellow;">},</mark>

Step 7. Deploy Contract

<mark style="background-color:yellow;">npx hardhat run --network \<your-network> scripts/deploy-stars-token.js</mark>

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 <mark style="background-color:yellow;">smart-contract-example/truffle</mark> folder

<mark style="background-color:yellow;">$ cd stars-smart-contract-example/truffle</mark>

Step 2. Run <mark style="background-color:yellow;">npm install</mark> inside the folder

<mark style="background-color:yellow;">$ npm install</mark>

Step 3. Make a copy of <mark style="background-color:yellow;">.env.example to .env</mark>

<mark style="background-color:yellow;">$ cp .env.example .env</mark>

Step 4. Modify <mark style="background-color:yellow;">.env</mark> and fill ONE of the fields

<mark style="background-color:yellow;">MNEMONIC=goose easy ivory ...</mark>

<mark style="background-color:yellow;">PRIVATE\_KEY=XXXXXXX</mark>

Step 5. Review Migration Script at

<mark style="background-color:yellow;">migrations/2\_deploy\_stars\_token.js</mark>

<mark style="background-color:yellow;">const StarsToken = artifacts.require("StarsToken");</mark>

<mark style="background-color:yellow;">module.exports = function (deployer) {</mark>

<mark style="background-color:yellow;">deployer.deploy(StarsToken, "Stars Token", "PT", "1000000000000000000000000");</mark>

<mark style="background-color:yellow;">};</mark>

Step 6. Endpoints setting

By default, the script will be using your local host <mark style="background-color:yellow;">"127.0.0.1"</mark> - If you are not running a localhost, you may leverage the public endpoint <mark style="background-color:yellow;"><http://13.213.36.146:6868></mark> by making changes to networks <mark style="background-color:yellow;">ins truffle-config.</mark>j, for example:

<mark style="background-color:yellow;">networks: {</mark>

<mark style="background-color:yellow;">development: {</mark>

<mark style="background-color:yellow;">provider: new HDWalletProvider(getHDWallet(), "<http://127.0.0.1:8545>"), // TODO</mark>

<mark style="background-color:yellow;">network\_id: "\*", // Any network (default: none)</mark>

<mark style="background-color:yellow;">},</mark>

<mark style="background-color:yellow;">testnet: {</mark>

<mark style="background-color:yellow;">provider: new HDWalletProvider(getHDWallet(), "<http://13.213.36.146:6868/>"), // TODO</mark>

<mark style="background-color:yellow;">network\_id: "\*",</mark>

<mark style="background-color:yellow;">skipDryRun: true</mark>

<mark style="background-color:yellow;">},</mark>

<mark style="background-color:yellow;">},</mark>

Step 7. Deploy Contract

<mark style="background-color:yellow;">truffle deployed --network \<your-network></mark>

\ <br>
