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
Create a configuration file to initialize Wagmi with Polkadot Hub. In your project, create a file named `src/lib/wagmi.ts` and add the code below. Be sure to replace `INSERT_RPC_URL`, `INSERT_CHAIN_ID`, `INSERT_CHAIN_NAME`, `INSERT_NETWORK_NAME`, `INSERT_CHAIN_DECIMALS`, `INSERT_CURRENCY_NAME`, and `INSERT_CURRENCY_SYMBOL` with your specific values.
35
+
Create a configuration file to initialize Wagmi with Polkadot Hub. In your project, create a file named `app/lib/wagmi.ts` and add the code below. Be sure to replace `INSERT_RPC_URL`, `INSERT_CHAIN_ID`, `INSERT_CHAIN_NAME`, `INSERT_NETWORK_NAME`, `INSERT_CHAIN_DECIMALS`, `INSERT_CURRENCY_NAME`, and `INSERT_CURRENCY_SYMBOL` with your specific values.
36
36
37
37
```typescript title="app/lib/wagmi.ts"
38
38
import { http, createConfig } from'wagmi'
@@ -248,7 +248,7 @@ This guide uses a simple Storage contract already deployed to the Polkadot Hub T
248
248
}
249
249
```
250
250
251
-
Create a component to interact with your deployed contract. Create a file named `components/StorageContract.tsx`:
251
+
Create a component to interact with your deployed contract. Create a file named `app/components/StorageContract.tsx`:
Copy file name to clipboardExpand all lines: .ai/pages/smart-contracts-libraries-web3-js.md
+5-8Lines changed: 5 additions & 8 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.
0 commit comments