Skip to content

Commit 25ce903

Browse files
nhussein11BigTavabee344eshaben
authored
[FIX] - Update hardhat guide according to latest releases of hardhat-polkadot (#623)
* hardhat: fix docs according to expected kusama launch (#563) * hardhat: fix docs according to expected kusama launch * fix: title * feat: proposes hardhat.config and hardhat.md * fix: rename polkadotTestnest to westendHub * fix: replaces `npx hardhat node` with `npx hardhat node-polkavm` * docs: small changes in "Use Hardhat with Polkadot" * docs: minor fixes * fix: tested and adjusting snippets * Apply suggestions from code review Co-authored-by: Alberto Nicolas Penayo <[email protected]> * fix: optimizer settings * Update develop/smart-contracts/dev-environments/hardhat.md Co-authored-by: Alberto Nicolas Penayo <[email protected]> * fix: missing polkavm true * fix: docs * fix: placeholder * Apply suggestions from code review Co-authored-by: Erin Shaben <[email protected]> * fix: feedback --------- Co-authored-by: Tiago Tavares ⭕️ <[email protected]> Co-authored-by: Alberto Nicolas Penayo <[email protected]> Co-authored-by: Erin Shaben <[email protected]>
1 parent 7cb1054 commit 25ce903

File tree

5 files changed

+353
-455
lines changed

5 files changed

+353
-455
lines changed

.snippets/code/develop/smart-contracts/dev-environments/hardhat/hardhat.config.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
// hardhat.config.js
22
require('@nomicfoundation/hardhat-toolbox');
33

4-
require('@nomicfoundation/hardhat-network-helpers');
5-
require('@nomicfoundation/hardhat-chai-matchers');
6-
require('@nomicfoundation/hardhat-ethers');
7-
require('hardhat-gas-reporter');
8-
require('@nomicfoundation/hardhat-ignition');
9-
10-
require('hardhat-resolc');
11-
require('hardhat-revive-node');
12-
13-
require('dotenv').config();
4+
require('@parity/hardhat-polkadot');
145

156
/** @type import('hardhat/config').HardhatUserConfig */
167
module.exports = {
178
solidity: '0.8.28',
18-
// Remix Compiler
9+
// npm Compiler
1910
resolc: {
2011
version: '1.5.2',
21-
compilerSource: 'remix',
12+
compilerSource: 'npm',
2213
settings: {
2314
optimizer: {
24-
enabled: false,
25-
runs: 600,
15+
enabled: true,
16+
parameters: 'z',
17+
fallbackOz: true,
18+
runs: 200,
2619
},
27-
evmVersion: 'istanbul',
2820
},
2921
},
3022
// Binary Compiler
@@ -33,7 +25,9 @@ module.exports = {
3325
settings: {
3426
optimizer: {
3527
enabled: true,
36-
runs: 400,
28+
parameters: 'z',
29+
fallbackOz: true,
30+
runs: 200,
3731
},
3832
evmVersion: 'istanbul',
3933
compilerPath: 'INSERT_PATH_TO_RESOLC_COMPILER',
@@ -57,7 +51,7 @@ module.exports = {
5751
polkavm: true,
5852
url: `http://127.0.0.1:8545`,
5953
},
60-
westendAssetHub: {
54+
westendHub: {
6155
polkavm: true,
6256
url: 'https://westend-asset-hub-eth-rpc.polkadot.io',
6357
accounts: [process.env.PRIVATE_KEY],

.snippets/code/develop/smart-contracts/dev-environments/hardhat/interact.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
const hre = require('hardhat');
22

33
async function main() {
4-
// Get the contract instance
5-
const Lock = await hre.ethers.getContractFactory('Lock');
6-
const contractAddress = '0x46E0a43DC905a5b8FA9Fc4dA61774abE31a098a5';
7-
const lock = await Lock.attach(contractAddress);
4+
// Get the contract factory
5+
const MyToken = await hre.ethers.getContractFactory('MyToken');
86

9-
// Read contract state
10-
const unlockTime = await lock.unlockTime();
7+
// Replace with your deployed contract address
8+
const contractAddress = 'INSERT_CONTRACT_ADDRESS';
9+
10+
// Attach to existing contract
11+
const token = await MyToken.attach(contractAddress);
1112

12-
const unlockTimestamp = Number(unlockTime);
13-
console.log(`Unlock time: ${new Date(unlockTimestamp)}`);
13+
// Get signers
14+
const [deployer] = await hre.ethers.getSigners();
1415

15-
const balance = await hre.ethers.provider.getBalance(lock.target);
16-
console.log(`Contract balance: ${hre.ethers.formatEther(balance)} ETH`);
16+
// Read contract state
17+
const name = await token.name();
18+
const symbol = await token.symbol();
19+
const totalSupply = await token.totalSupply();
20+
const balance = await token.balanceOf(deployer.address);
1721

18-
// Interact with contract (transaction)
19-
try {
20-
const tx = await lock.withdraw();
21-
await tx.wait();
22-
console.log('Withdrawal successful!');
23-
} catch (error) {
24-
console.error(`Error during withdrawal: ${error.message}`);
25-
}
22+
console.log(`Token: ${name} (${symbol})`);
23+
console.log(
24+
`Total Supply: ${hre.ethers.formatUnits(totalSupply, 18)} tokens`
25+
);
26+
console.log(
27+
`Deployer Balance: ${hre.ethers.formatUnits(balance, 18)} tokens`
28+
);
2629
}
2730

2831
main().catch((error) => {

0 commit comments

Comments
 (0)