Skip to content

Commit c8c4856

Browse files
committed
fix: ethersjs snippets and rendering
1 parent 7bf160a commit c8c4856

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const compileContract = async (solidityFilePath, outputDir) => {
3030
const bytecodePath = join(outputDir, `${name}.polkavm`);
3131
writeFileSync(
3232
bytecodePath,
33-
Buffer.from(contract.evm.bytecode.object, 'hex')
33+
Buffer.from(contract.evm.bytecode.object, 'hex'),
3434
);
3535
console.log(`Bytecode saved to ${bytecodePath}`);
3636
}
@@ -40,7 +40,7 @@ const compileContract = async (solidityFilePath, outputDir) => {
4040
}
4141
};
4242

43-
const solidityFilePath = './Storage.sol';
44-
const outputDir = '.';
43+
const solidityFilePath = join(__dirname, '../contracts/Storage.sol');
44+
const outputDir = join(__dirname, '../contracts');
4545

4646
compileContract(solidityFilePath, outputDir);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Deploy an EVM-compatible smart contract using ethers.js
12
const { writeFileSync, existsSync, readFileSync } = require('fs');
23
const { join } = require('path');
34
const { ethers, JsonRpcProvider } = require('ethers');

develop/smart-contracts/libraries/ethers-js.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,31 +153,31 @@ You can create a `deploy.js` script in the root of your project to achieve this.
153153
1. Set up the required imports and utilities:
154154

155155
```js title="scripts/deploy.js"
156-
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:1:5'
156+
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:1:6'
157157
```
158158

159159
2. Create a provider to connect to Polkadot Hub:
160160

161161
```js title="scripts/deploy.js"
162-
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:6:14'
162+
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:7:15'
163163
```
164-
164+
r2
165165
3. Set up functions to read contract artifacts:
166166

167167
```js title="scripts/deploy.js"
168-
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:16:44'
168+
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:17:45'
169169
```
170170

171171
4. Create the main deployment function:
172172

173173
```js title="scripts/deploy.js"
174-
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:46:81'
174+
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:47:82'
175175
```
176176

177177
5. Configure and execute the deployment:
178178

179179
```js title="scripts/deploy.js"
180-
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:83:92'
180+
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:84:92'
181181
```
182182

183183
!!! note
@@ -188,7 +188,7 @@ You can create a `deploy.js` script in the root of your project to achieve this.
188188
??? code "View complete script"
189189
190190
```js title="scripts/deploy.js"
191-
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js'
191+
--8<-- 'code/develop/smart-contracts/evm-toolkit/ethers-js/deploy.js:1'
192192
```
193193
194194
To run the script, execute the following command:

llms.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8913,7 +8913,7 @@ const compileContract = async (solidityFilePath, outputDir) => {
89138913
const bytecodePath = join(outputDir, `${name}.polkavm`);
89148914
writeFileSync(
89158915
bytecodePath,
8916-
Buffer.from(contract.evm.bytecode.object, 'hex')
8916+
Buffer.from(contract.evm.bytecode.object, 'hex'),
89178917
);
89188918
console.log(`Bytecode saved to ${bytecodePath}`);
89198919
}
@@ -8923,8 +8923,8 @@ const compileContract = async (solidityFilePath, outputDir) => {
89238923
}
89248924
};
89258925

8926-
const solidityFilePath = './Storage.sol';
8927-
const outputDir = '.';
8926+
const solidityFilePath = join(__dirname, '../contracts/Storage.sol');
8927+
const outputDir = join(__dirname, '../contracts');
89288928

89298929
compileContract(solidityFilePath, outputDir);
89308930
```
@@ -8951,7 +8951,8 @@ You can create a `deploy.js` script in the root of your project to achieve this.
89518951
1. Set up the required imports and utilities:
89528952

89538953
```js title="scripts/deploy.js"
8954-
const { join } = require('path');
8954+
const { writeFileSync, existsSync, readFileSync } = require('fs');
8955+
const { join } = require('path');
89558956
const { ethers, JsonRpcProvider } = require('ethers');
89568957

89578958
const codegenDir = join(__dirname);
@@ -8969,7 +8970,7 @@ const createProvider = (rpcUrl, chainId, chainName) => {
89698970
return provider;
89708971
};
89718972
```
8972-
8973+
r2
89738974
3. Set up functions to read contract artifacts:
89748975

89758976
```js title="scripts/deploy.js"
@@ -9064,7 +9065,8 @@ deployContract('Storage', mnemonic, providerConfig);
90649065
??? code "View complete script"
90659066

90669067
```js title="scripts/deploy.js"
9067-
const { writeFileSync, existsSync, readFileSync } = require('fs');
9068+
// Deploy an EVM-compatible smart contract using ethers.js
9069+
const { writeFileSync, existsSync, readFileSync } = require('fs');
90689070
const { join } = require('path');
90699071
const { ethers, JsonRpcProvider } = require('ethers');
90709072

0 commit comments

Comments
 (0)