Deploy the contract
Deploy the contract locally is fine for doing simple tests, but we recommend to target the Etherlink Testnet to run complete scenarios as you may depend on other services like block explorers, oracles, etc.
-
Deploy the contract locally with Hardhat:
-
Prepare a module for the ignition plugin of Hardhat. The module is used as the default script for deployment. Rename the default file first:
mv ./ignition/modules/Counter.ts ./ignition/modules/Marketpulse.ts -
Replace the contents of the file with this code:
// This setup uses Hardhat Ignition to manage smart contract deployments.
// Learn more about it at https://hardhat.org/ignition
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
const MarketpulseModule = buildModule("MarketpulseModule", (m) => {
const MarketpulseContract = m.contract("Marketpulse", []);
m.call(MarketpulseContract, "ping", []);
return { MarketpulseContract };
});
export default MarketpulseModule;This module deploys the contract and calls the Ping endpoint to verify that it deployed well.
-
Start a local Ethereum node:
npx hardhat node -
In a different terminal window, deploy the contract using Hardhat ignition:
npx hardhat ignition deploy ignition/modules/Marketpulse.ts --reset --network localhostYou can deploy the contract to any local Ethereum node but Etherlink is a good choice because it is persistent and free and most tools and indexers are already deployed on it.
The response looks like this:
Hardhat Ignition 🚀
Deploying [ MarketpulseModule ]
Batch #1
Executed MarketpulseModule#Marketpulse
Batch #2
Executed MarketpulseModule#Marketpulse.ping
[ MarketpulseModule ] successfully deployed 🚀
Deployed Addresses
MarketpulseModule#Marketpulse - 0x5FbDB2315678afecb367f032d93F642f64180aa3
-
-
Check that your deployment logs do not contain any error and stop the Hardhat node.
-
Deploy the contract on Etherlink Shadownet Testnet:
-
In the Hardhat configuration file
hardhat.config.ts, add Etherlink Mainnet and Shadownet Testnet as custom networks by replacing the default file with this code:import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem";
import { configVariable, defineConfig } from "hardhat/config";
if (!configVariable("DEPLOYER_PRIVATE_KEY")) {
console.error("Missing env var DEPLOYER_PRIVATE_KEY");
}
const deployerPrivateKey = configVariable("DEPLOYER_PRIVATE_KEY");
export default defineConfig({
plugins: [hardhatToolboxViemPlugin],
solidity: {
profiles: {
default: {
version: "0.8.28",
},
production: {
version: "0.8.28",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
},
},
networks: {
hardhatMainnet: {
type: "edr-simulated",
chainType: "l1",
},
hardhatOp: {
type: "edr-simulated",
chainType: "op",
},
etherlinkMainnet: {
type: "http",
url: "https://node.mainnet.etherlink.com",
accounts: [deployerPrivateKey],
},
etherlinkShadownet: {
type: "http",
url: "https://node.shadownet.etherlink.com",
accounts: [deployerPrivateKey],
},
},
chainDescriptors: {
127823: {
chainType: "generic",
name: "etherlinkShadownet",
blockExplorers: {
etherscan: {
name: "EtherlinkExplorer",
apiUrl: "https://shadownet.explorer.etherlink.com/api",
url: "https://shadownet.explorer.etherlink.com",
},
blockscout: {
name: "EtherlinkExplorer",
apiUrl: "https://shadownet.explorer.etherlink.com/api",
url: "https://shadownet.explorer.etherlink.com",
},
},
},
42793: {
name: "EtherlinkMainnet",
}
},
verify: {
blockscout: {
enabled: true,
},
etherscan: {
apiKey: "DUMMY",
enabled: true,
},
sourcify: {
enabled: false,
}
}
}); -
Set up an Etherlink Shadownet Testnet account with some native tokens to deploy the contract. See Using your wallet connect your wallet to Etherlink. Then use the faucet to get XTZ tokens on Etherlink Shadownet Testnet, as described in Getting testnet tokens.
-
Export your account private key from your wallet application.
-
Set the private key (represented in this example as
<YOUR_ETHERLINK_KEY>) as the value of theDEPLOYER_PRIVATE_KEYenvironment variable by running this command:export DEPLOYER_PRIVATE_KEY=<YOUR_ETHERLINK_KEY> -
Deploy the contract to Etherlink Shadownet Testnet network specifying the
--networkoption:npx hardhat ignition deploy ignition/modules/Marketpulse.ts --network etherlinkShadownetA successful output should look like this:
Hardhat Ignition 🚀
Deploying [ MarketpulseModule ]
Batch #1
Executed MarketpulseModule#Marketpulse
Batch #2
Executed MarketpulseModule#Marketpulse.ping
[ MarketpulseModule ] successfully deployed 🚀
Deployed Addresses
MarketpulseModule#Marketpulse - 0xc64Bc334cf7a6b528357F8E88bbB3712E98629FF
-
-
Run this command to verify your deployed contract, using the contract address as the value of
<CONTRACT_ADDRESS>:npx hardhat verify --network etherlinkShadownet <CONTRACT_ADDRESS>The response should include the message "Successfully verified contract Marketpulse on the block explorer" and a link to the block explorer.
You can also pass the
--verifyoption to the deployment command to verify the contract as part of the deployment process.
The next step is to create the frontend application.