-
Notifications
You must be signed in to change notification settings - Fork 74
Fix - Ethersjs library page now using EVM #1241
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
0638be4
4009f7f
c94b9ac
2400916
926bdd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,11 +1,11 @@ | ||||||
| // Deploy an EVM-compatible smart contract using ethers.js | ||||||
| const { writeFileSync, existsSync, readFileSync } = require('fs'); | ||||||
| const { join } = require('path'); | ||||||
| const { ethers, JsonRpcProvider } = require('ethers'); | ||||||
|
|
||||||
| const codegenDir = join(__dirname); | ||||||
| const scriptsDir = __dirname; | ||||||
| const artifactsDir = join(__dirname, '../contracts'); | ||||||
|
|
||||||
| // Creates an Ethereum provider with specified RPC URL and chain details | ||||||
| // Creates a provider with specified RPC URL and chain details | ||||||
| const createProvider = (rpcUrl, chainId, chainName) => { | ||||||
| const provider = new JsonRpcProvider(rpcUrl, { | ||||||
| chainId: chainId, | ||||||
|
|
@@ -17,9 +17,8 @@ const createProvider = (rpcUrl, chainId, chainName) => { | |||||
| // Reads and parses the ABI file for a given contract | ||||||
| const getAbi = (contractName) => { | ||||||
| try { | ||||||
| return JSON.parse( | ||||||
| readFileSync(join(codegenDir, `${contractName}.json`), 'utf8'), | ||||||
| ); | ||||||
| const abiPath = join(artifactsDir, `${contractName}.json`); | ||||||
| return JSON.parse(readFileSync(abiPath, 'utf8')); | ||||||
| } catch (error) { | ||||||
| console.error( | ||||||
| `Could not find ABI for contract ${contractName}:`, | ||||||
|
|
@@ -32,12 +31,10 @@ const getAbi = (contractName) => { | |||||
| // Reads the compiled bytecode for a given contract | ||||||
| const getByteCode = (contractName) => { | ||||||
| try { | ||||||
| const bytecodePath = join( | ||||||
| codegenDir, | ||||||
| '../contracts', | ||||||
| `${contractName}.polkavm`, | ||||||
| ); | ||||||
| return `0x${readFileSync(bytecodePath).toString('hex')}`; | ||||||
| const bytecodePath = join(artifactsDir, `${contractName}.bin`); | ||||||
| const bytecode = readFileSync(bytecodePath, 'utf8').trim(); | ||||||
| // Add 0x prefix if not present | ||||||
| return bytecode.startsWith('0x') ? bytecode : `0x${bytecode}`; | ||||||
| } catch (error) { | ||||||
| console.error( | ||||||
| `Could not find bytecode for contract ${contractName}:`, | ||||||
|
|
@@ -49,7 +46,6 @@ const getByteCode = (contractName) => { | |||||
|
|
||||||
| const deployContract = async (contractName, mnemonic, providerConfig) => { | ||||||
| console.log(`Deploying ${contractName}...`); | ||||||
|
|
||||||
| try { | ||||||
| // Step 1: Set up provider and wallet | ||||||
| const provider = createProvider( | ||||||
|
|
@@ -73,10 +69,11 @@ const deployContract = async (contractName, mnemonic, providerConfig) => { | |||||
| const address = await contract.getAddress(); | ||||||
| console.log(`Contract ${contractName} deployed at: ${address}`); | ||||||
|
|
||||||
| const addressesFile = join(codegenDir, 'contract-address.json'); | ||||||
| const addressesFile = join(scriptsDir, 'contract-address.json'); | ||||||
| const addresses = existsSync(addressesFile) | ||||||
| ? JSON.parse(readFileSync(addressesFile, 'utf8')) | ||||||
| : {}; | ||||||
|
|
||||||
| addresses[contractName] = address; | ||||||
| writeFileSync(addressesFile, JSON.stringify(addresses, null, 2), 'utf8'); | ||||||
| } catch (error) { | ||||||
|
|
@@ -85,11 +82,11 @@ const deployContract = async (contractName, mnemonic, providerConfig) => { | |||||
| }; | ||||||
|
|
||||||
| const providerConfig = { | ||||||
| rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io', | ||||||
| rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io', #TODO: replace to `https://services.polkadothub-rpc.com/testnet` when ready | ||||||
|
||||||
| rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io', #TODO: replace to `https://services.polkadothub-rpc.com/testnet` when ready | |
| rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io', // TODO: replace to `https://services.polkadothub-rpc.com/testnet` when ready |
Copilot
AI
Nov 17, 2025
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.
The mnemonic phrase is hardcoded in the deployment script. This is a security risk as it exposes private keys in the codebase. The placeholder INSERT_MNEMONIC should be kept instead, or the script should read from environment variables.
Replace:
const mnemonic = 'evoke moment pluck misery cheese boy era fresh useful frame resemble cinnamon';With:
const mnemonic = 'INSERT_MNEMONIC';Or better yet, use environment variables:
const mnemonic = process.env.MNEMONIC || 'INSERT_MNEMONIC';| const mnemonic = 'evoke moment pluck misery cheese boy era fresh useful frame resemble cinnamon'; | |
| const mnemonic = process.env.MNEMONIC || 'INSERT_MNEMONIC'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.9; | ||
|
|
||
| contract Storage { | ||
| uint256 private storedNumber; | ||
|
|
||
| event NumberUpdated(uint256 newValue); | ||
|
|
||
| function store(uint256 num) public { | ||
| storedNumber = num; | ||
| emit NumberUpdated(num); | ||
| } | ||
|
|
||
| function retrieve() public view returns (uint256) { | ||
| return storedNumber; | ||
| } | ||
| } |
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.
There's a TODO comment left in production code that should be addressed or removed before merging. If the URL change is pending, consider documenting this separately or creating a follow-up issue.
The line reads:
Either complete the change or remove the TODO comment.