You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .ai/pages/smart-contracts-libraries-web3-js.md
+7-10Lines changed: 7 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,9 +73,6 @@ Add the Solidity compiler so you can generate standard EVM bytecode:
73
73
npm install --save-dev solc
74
74
```
75
75
76
-
!!! tip
77
-
The sample scripts use ECMAScript modules. Add `"type": "module"` to your `package.json` (or rename the files to `.mjs`) so that `node` can run the `import` statements.
78
-
79
76
## Set Up the Web3 Provider
80
77
81
78
The provider configuration is the foundation of any Web3.js application. It serves as a bridge between your application and the blockchain, allowing you to query blockchain data and interact with smart contracts.
@@ -132,7 +129,7 @@ With the provider set up, you can start querying the blockchain. For instance, t
@@ -395,7 +392,7 @@ You can create a `deploy.js` script in the `scripts` directory of your project t
395
392
const providerConfig = {
396
393
rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io', // TODO: replace to `https://services.polkadothub-rpc.com/testnet` when ready
397
394
chainId:420420422,
398
-
name:'polkadot-hub-testnet',
395
+
name:'polkadotTestNet',
399
396
};
400
397
401
398
constprivateKey='INSERT_PRIVATE_KEY';
@@ -503,7 +500,7 @@ You can create a `deploy.js` script in the `scripts` directory of your project t
503
500
const providerConfig = {
504
501
rpc: 'https://testnet-passet-hub-eth-rpc.polkadot.io', // TODO: replace to `https://services.polkadothub-rpc.com/testnet` when ready
505
502
chainId:420420422,
506
-
name:'polkadot-hub-testnet',
503
+
name:'polkadotTestNet',
507
504
};
508
505
509
506
constprivateKey='INSERT_PRIVATE_KEY';
@@ -523,7 +520,7 @@ After running this script, your contract will be deployed to Polkadot Hub, and i
523
520
524
521
## Interact with the Contract
525
522
526
-
Once the contract is deployed, you can interact with it by calling its functions. For example, to set a number, read it and then modify that number by its double, you can create a file named `updateStorage.js`in the `scripts` directory of your project and add the following code:
523
+
Once the contract is deployed, you can interact with it by calling its functions. For example, to read the current stored value and then update it to a newvalue, you can create a file named `updateStorage.js`in the `scripts` directory of your project and add the following code:
527
524
528
525
```js title="scripts/updateStorage.js"
529
526
const { readFileSync } = require('fs');
@@ -593,7 +590,7 @@ updateStorage(config)
593
590
.catch((error) => console.error('Update error'));
594
591
```
595
592
596
-
Ensure you replace the `INSERT_MNEMONIC`, `INSERT_CONTRACT_ADDRESS`, and `INSERT_ADDRESS_TO_CHECK` placeholders with actual values. Also, ensure the contract ABIfile (`Storage.json`) is correctly referenced. The script prints the balance for`ADDRESS_TO_CHECK` before it writes and doubles the stored value, so pick any account you want to monitor.
593
+
Ensure you replace the `INSERT_PRIVATE_KEY`and `INSERT_CONTRACT_ADDRESS` placeholders with actual values. Also, ensure the contract ABIfile (`Storage.json`) is correctly referenced. The script reads the current stored value, sets it to 1, and then displays the updated value.
597
594
598
595
To interact with the contract, run:
599
596
@@ -609,8 +606,8 @@ node scripts/updateStorage.js
609
606
610
607
---
611
608
612
-
Explore the Web3.js documentation to learn how to use additional features, such as wallet management, signing messages, subscribing to events, etc.
609
+
Explore the Web3.js documentation to learn how to use additional features, such as wallet management, signing messages, subscribing to events, and more.
613
610
614
-
[:octicons-arrow-right-24: Get Started](https://web3js.readthedocs.io/en/v1.10.0/)
0 commit comments