Skip to content

Commit a7235ac

Browse files
committed
fix: deployjs script
1 parent c8c4856 commit a7235ac

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

.snippets/code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ const getAbi = (contractName) => {
3232
// Reads the compiled bytecode for a given contract
3333
const getByteCode = (contractName) => {
3434
try {
35-
return `0x${readFileSync(
36-
join(codegenDir, `${contractName}.polkavm`),
37-
).toString('hex')}`;
35+
const bytecodePath = join(
36+
codegenDir,
37+
'../contracts',
38+
`${contractName}.polkavm`,
39+
);
40+
return `0x${readFileSync(bytecodePath).toString('hex')}`;
3841
} catch (error) {
3942
console.error(
4043
`Could not find bytecode for contract ${contractName}:`,

llms.txt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8991,23 +8991,26 @@ r2
89918991
// Reads the compiled bytecode for a given contract
89928992
const getByteCode = (contractName) => {
89938993
try {
8994-
return `0x${readFileSync(
8995-
join(codegenDir, `${contractName}.polkavm`),
8996-
).toString('hex')}`;
8994+
const bytecodePath = join(
8995+
codegenDir,
8996+
'../contracts',
8997+
`${contractName}.polkavm`,
8998+
);
8999+
return `0x${readFileSync(bytecodePath).toString('hex')}`;
89979000
} catch (error) {
89989001
console.error(
89999002
`Could not find bytecode for contract ${contractName}:`,
90009003
error.message,
90019004
);
9002-
throw error;
9003-
}
9004-
};
90059005
```
90069006

90079007
4. Create the main deployment function:
90089008

90099009
```js title="scripts/deploy.js"
9010-
console.log(`Deploying ${contractName}...`);
9010+
};
9011+
9012+
const deployContract = async (contractName, mnemonic, providerConfig) => {
9013+
console.log(`Deploying ${contractName}...`);
90119014

90129015
try {
90139016
// Step 1: Set up provider and wallet
@@ -9039,22 +9042,18 @@ const getByteCode = (contractName) => {
90399042
addresses[contractName] = address;
90409043
writeFileSync(addressesFile, JSON.stringify(addresses, null, 2), 'utf8');
90419044
} catch (error) {
9042-
console.error(`Failed to deploy contract ${contractName}:`, error);
9043-
}
9044-
};
90459045
```
90469046

90479047
5. Configure and execute the deployment:
90489048

90499049
```js title="scripts/deploy.js"
9050-
rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io',
9050+
};
9051+
9052+
const providerConfig = {
9053+
rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io',
90519054
chainId: 420420422,
90529055
name: 'polkadot-hub-testnet',
90539056
};
9054-
9055-
const mnemonic = 'INSERT_MNEMONIC';
9056-
9057-
deployContract('Storage', mnemonic, providerConfig);
90589057
```
90599058

90609059
!!! note
@@ -9099,9 +9098,12 @@ const getAbi = (contractName) => {
90999098
// Reads the compiled bytecode for a given contract
91009099
const getByteCode = (contractName) => {
91019100
try {
9102-
return `0x${readFileSync(
9103-
join(codegenDir, `${contractName}.polkavm`),
9104-
).toString('hex')}`;
9101+
const bytecodePath = join(
9102+
codegenDir,
9103+
'../contracts',
9104+
`${contractName}.polkavm`,
9105+
);
9106+
return `0x${readFileSync(bytecodePath).toString('hex')}`;
91059107
} catch (error) {
91069108
console.error(
91079109
`Could not find bytecode for contract ${contractName}:`,

0 commit comments

Comments
 (0)