Skip to content

Commit 2ab431e

Browse files
authored
Fix async context in onchain client examples
Updated the Ethers.js and Viem examples in `src/pages/build/onchain-clients.mdx` to wrap `await` calls in an explicit `async` function, since both examples previously used `await` without providing an async execution context.
1 parent 5ad85c4 commit 2ab431e

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

src/pages/build/onchain-clients.mdx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ To connect to Ink by instantiating a new `ethers.js` `JsonRpcProvider` object wi
2525

2626
const rpcUrl = 'https://rpc-gel-sepolia.inkonchain.com';
2727
const provider = new ethers.JsonRpcProvider(rpcUrl, 763373);
28+
29+
async function main() {
30+
const blockNumber = await provider.getBlockNumber();
31+
console.log(blockNumber);
32+
}
33+
34+
main().catch(console.error);
2835
```
2936

3037
3. **Using the Provider**: You can now use the `provider` to interact with Ink's testnet. For example, you can fetch the current block number or interact with smart contracts deployed on the testnet.
3138

32-
```javascript
33-
// previous code
34-
const blockNumber = await provider.getBlockNumber();
35-
console.log(blockNumber);
36-
```
37-
3839
### Example: Fetching the Current Block Number
3940

4041
The following code snippet demonstrates how to fetch and print the current block number from Ink's testnet:
@@ -64,12 +65,13 @@ Viem documentation: [https://viem.sh/docs/introduction](https://viem.sh/docs/int
6465
chain: inkSepolia,
6566
transport: http(),
6667
})
68+
69+
async function main() {
70+
const blockNumber = await client.getBlockNumber();
71+
console.log(blockNumber);
72+
}
73+
74+
main().catch(console.error);
6775
```
6876

6977
3. **Consuming Actions**: You can now interact with Ink's chain! Here we are getting the current block number.
70-
71-
```javascript
72-
// previous code
73-
const blockNumber = await client.getBlockNumber();
74-
console.log(blockNumber);
75-
```

0 commit comments

Comments
 (0)