-
Notifications
You must be signed in to change notification settings - Fork 75
Cleanup smart contracts/cookbook/EVM smart contracts #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging/product-ia
Are you sure you want to change the base?
Changes from all commits
70701b4
9705924
95d4479
6076bb9
0f355af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.9; | ||
|
|
||
| contract Storage { | ||
| uint256 private storedNumber; | ||
|
|
||
| function store(uint256 num) public { | ||
| storedNumber = num; | ||
| } | ||
|
|
||
| function retrieve() public view returns (uint256) { | ||
| return storedNumber; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <div id="termynal" data-termynal> | ||
| <span data-ty="input"><span class="file-path"></span>npx hardhat compile</span> | ||
| <span data-ty>Downloading solc 0.8.28</span> | ||
| <span data-ty>Downloading solc 0.8.28 (WASM build)</span> | ||
| <span data-ty>Compiled 1 Solidity file with solc 0.8.28 (evm target: cancun)</span> | ||
| <span data-ty="input"><span class="file-path"></span></span> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type { HardhatUserConfig } from 'hardhat/config'; | ||
|
|
||
| import hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem'; | ||
| import { configVariable } from 'hardhat/config'; | ||
|
|
||
| const config: HardhatUserConfig = { | ||
| 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', | ||
| }, | ||
| sepolia: { | ||
| type: 'http', | ||
| chainType: 'l1', | ||
| url: configVariable('SEPOLIA_RPC_URL'), | ||
| accounts: [configVariable('SEPOLIA_PRIVATE_KEY')], | ||
| }, | ||
| polkadotHubTestnet: { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, should have shared before, but Nico said we should follow these conventions: revive dev node -> localNode -> rpc: localhost:8545 So can you please rename this to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, just saw we're using So let's do that here please |
||
| url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', | ||
| chainId: 420420422, | ||
| accounts: [configVariable('PRIVATE_KEY')], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default config; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'; | ||
|
|
||
| export default buildModule('StorageModule', (m) => { | ||
| const storage = m.contract('Storage'); | ||
| return { storage }; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <div id="termynal" data-termynal markdown> | ||
| <span data-ty="input">npx hardhat compile</span> | ||
| <span data-ty>Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6</span> | ||
| <span data-ty>Successfully generated 62 typings!</span> | ||
| <span data-ty>Compiled 21 Solidity files successfully (evm target: paris).</span> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <div id="termynal" data-termynal markdown> | ||
| <span data-ty="input">npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet</span> | ||
| <span data-ty>✔ Confirm deploy to network polkadotTestnet (420420420)? … yes</span> | ||
| <span data-ty> </span> | ||
| <span data-ty>Hardhat Ignition 🚀</span> | ||
| <span data-ty> </span> | ||
| <span data-ty>Deploying [ TokenModule ]</span> | ||
| <span data-ty> </span> | ||
| <span data-ty>Batch #1</span> | ||
| <span data-ty> Executed TokenModule#MyToken</span> | ||
| <span data-ty> </span> | ||
| <span data-ty>Batch #2</span> | ||
| <span data-ty> Executed TokenModule#MyToken.mint</span> | ||
| <span data-ty> </span> | ||
| <span data-ty>[ TokenModule ] successfully deployed 🚀</span> | ||
| <span data-ty> </span> | ||
| <span data-ty>Deployed Addresses</span> | ||
| <span data-ty> </span> | ||
| <span data-ty>TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3</span> | ||
| </div> |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File path isn't correct, it should be |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <div id="termynal" data-termynal markdown> | ||
| <span data-ty="input">npx hardhat test --network polkadotTestnet</span> | ||
| <span data-ty></span> | ||
| <span data-ty> MyToken</span> | ||
| <span data-ty> Deployment</span> | ||
| <span data-ty> ✔ Should have correct name and symbol</span> | ||
| <span data-ty> ✔ Should set the right owner</span> | ||
| <span data-ty> ✔ Should have zero initial supply</span> | ||
| <span data-ty> Minting</span> | ||
| <span data-ty> ✔ Should allow owner to mint tokens</span> | ||
| <span data-ty> ✔ Should increase total supply on mint</span> | ||
| <span data-ty> Multiple mints</span> | ||
| <span data-ty> ✔ Should correctly track balance after multiple mints</span> | ||
| <span data-ty></span> | ||
| <span data-ty> 6 passing (369ms)</span> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
| import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
|
||
| contract MyNFT is ERC721, Ownable { | ||
| uint256 private _nextTokenId; | ||
|
|
||
| constructor( | ||
| address initialOwner | ||
| ) ERC721("MyToken", "MTK") Ownable(initialOwner) {} | ||
|
|
||
| function safeMint(address to) public onlyOwner { | ||
| uint256 tokenId = _nextTokenId++; | ||
| _safeMint(to, tokenId); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'; | ||
|
|
||
| export default buildModule('MyNFTModule', (m) => { | ||
| const initialOwner = m.getParameter('initialOwner', 'INSERT_OWNER_ADDRESS'); | ||
| const myNFT = m.contract('MyNFT', [initialOwner]); | ||
| return { myNFT }; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <div id="termynal" data-termynal> | ||
| <span data-ty="input"><span class="file-path"></span>npx hardhat compile</span> | ||
| <span data-ty>Downloading solc 0.8.28</span> | ||
| <span data-ty>Downloading solc 0.8.28 (WASM build)</span> | ||
| <span data-ty>Compiled 1 Solidity file with solc 0.8.28 (evm target: cancun)</span> | ||
| <span data-ty="input"><span class="file-path"></span></span> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import type { HardhatUserConfig } from 'hardhat/config'; | ||
|
|
||
| import hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem'; | ||
| import { configVariable } from 'hardhat/config'; | ||
|
|
||
| const config: HardhatUserConfig = { | ||
| 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', | ||
| }, | ||
| sepolia: { | ||
| type: 'http', | ||
| chainType: 'l1', | ||
| url: configVariable('SEPOLIA_RPC_URL'), | ||
| accounts: [configVariable('SEPOLIA_PRIVATE_KEY')], | ||
| }, | ||
| polkadotHubTestnet: { | ||
| type: 'http', | ||
| url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', | ||
| chainId: 420420422, | ||
| accounts: [configVariable('PRIVATE_KEY')], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default config; |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file path doesn't match the file, need to remove erc721 from the path so it's just |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
| import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
|
||
| contract MyNFT is ERC721, Ownable { | ||
| uint256 private _nextTokenId; | ||
|
|
||
| constructor( | ||
| address initialOwner | ||
| ) ERC721("MyToken", "MTK") Ownable(initialOwner) {} | ||
|
|
||
| function safeMint(address to) public onlyOwner { | ||
| uint256 tokenId = _nextTokenId++; | ||
| _safeMint(to, tokenId); | ||
| } | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some inconsistencies here with the numbers we're using. Can we make them all double-digit like
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also inconsistencies with the paths: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| nav: | ||
| - 'Deploy a Basic Contract': deploy-basic | ||
| - 'Deploy an ERC-20': deploy-erc20 | ||
| - 'Deploy an NFT': deploy-nft | ||
| - 'Deploy Basic Contract': deploy-basic | ||
| - 'Deploy ERC-20 Token': deploy-erc20 | ||
| - 'Deploy ERC-721 NFT': deploy-nft | ||
|
Comment on lines
+2
to
+4
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use the “verb + article + object” pattern in many other pages (e.g., “Create a DApp,” “Get Tokens From the Faucet”), so switching to titles like “Deploy Basic Contract” is a bit of an inconsistent change. So I think we should switch it back in this case |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| nav: | ||
| - 'Using Remix IDE': remix.md | ||
| - 'Using Hardhat': hardhat.md | ||
| - 'Remix IDE': basic-remix.md | ||
| - 'Hardhat': basic-hardhat.md | ||
| # - 'Using Foundry': foundry.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File path here doesn't match either can drop
-contractso it's justdeploy-basiclike the directory