Skip to content

Commit c81eef1

Browse files
committed
polygon
1 parent 0c03d73 commit c81eef1

File tree

3 files changed

+67
-108
lines changed

3 files changed

+67
-108
lines changed

fern/api-reference/ethereum/ethereum-api-quickstart.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ console.log(receipt);
9393

9494
# Ethereum Tutorials
9595

96-
You must not stop here! Check out the following tutorials to learn how to build with Ethereum:
96+
Check out the following tutorials to learn how to build with Ethereum:
9797

9898
* [Build a Web3 Dashboard](/docs/web3-dashboard-prompt)
9999
* [Ethereum Developer Guide to the Merge](/reference/ethereum-developer-guide-to-the-merge)
100100
* [How do I distinguish between a contract address and wallet address?](/reference/contract-address-vs-wallet-address)
101+
102+
For full documentation on Web3 libraries, check out the official documentation:
103+
104+
* [Viem Documentation](https://viem.sh) - Modern TypeScript interface for Ethereum
105+
* [Ethers.js Documentation](https://docs.ethers.org) - Complete Ethereum wallet implementation

fern/api-reference/polygon-pos/polygon-api-quickstart.mdx

Lines changed: 58 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,97 @@
11
---
22
title: Polygon PoS API Quickstart
3-
description: How to get started building on Polygon PoS and using the JSON-RPC API
3+
description: How to get started building on Polygon PoS and using
44
subtitle: How to get started building on Polygon PoS and using the JSON-RPC API
5-
slug: reference/polygon-pos-api-quickstart
5+
slug: docs/polygon-pos
66
---
77

8-
<Tip title="Don’t have an API key?" icon="star">
9-
Sign up to start building on Polygon. [Get started for free](https://dashboard.alchemy.com/signup)
8+
<Tip title="Don't have an API key?" icon="star">
9+
Build faster with production-ready APIs, smart wallets and rollup infrastructure across 70+ chains. Create your free Alchemy API key and{" "}
10+
<a href="https://dashboard.alchemy.com/signup">get started today</a>.
1011
</Tip>
1112

12-
# Getting Started Instructions
13+
## Send Your First Request on Alchemy
1314

14-
## 1. Choose a package manager (npm or yarn)
15-
16-
For this guide, we will be using npm or yarn as our package manager to install Viem or Ethers.js.
17-
18-
### npm
19-
20-
To get started with `npm`, follow the documentation to install Node.js and `npm` for your operating system: [https://docs.npmjs.com/downloading-and-installing-node-js-and-npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
21-
22-
### yarn
23-
24-
To get started with `yarn`, follow these steps: [https://classic.yarnpkg.com/lang/en/docs/install](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)
25-
26-
## 2. Set up your project (npm or yarn)
15+
Let's use the [`viem`](https://www.npmjs.com/package/viem) package to create an Ethereum client connected to Alchemy and fetch the latest block number!
2716

2817
<CodeGroup>
29-
```text Shell (npm)
30-
mkdir alchemy-polygon-api
31-
cd alchemy-polygon-api
32-
npm init --yes
18+
```text npm
19+
npm install --save viem
3320
```
3421

35-
```text Shell (yarn)
36-
mkdir alchemy-polygon-api
37-
cd alchemy-polygon-api
38-
yarn init --yes
22+
```text yarn
23+
yarn add viem
3924
```
4025
</CodeGroup>
4126

42-
## 3. Install Web3 Library
43-
44-
Run the following command to install Viem or Ethers.js with npm or yarn.
27+
## Create Client Connected to Alchemy
4528

4629
<CodeGroup>
47-
```text Viem (npm)
48-
npm install viem
49-
```
50-
51-
```text Viem (yarn)
52-
yarn add viem
53-
```
54-
55-
```text Ethers.js (npm)
56-
npm install ethers
57-
```
58-
59-
```text Ethers.js (yarn)
60-
yarn add ethers
61-
```
30+
```js
31+
import { createPublicClient, http } from "viem";
32+
import { mainnet } from "viem/chains";
33+
34+
const client = createPublicClient({
35+
chain: mainnet,
36+
transport: http("https://polygon-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY"),
37+
});
38+
```
6239
</CodeGroup>
6340

64-
## 4. Make your first request
41+
Now that you've created a client connected to Alchemy, you can continue with some basics:
6542

66-
You are all set now to use Polygon PoS API and make your first request. For instance, lets make a request to `get latest block`. Create an `index.js` file and paste one of the following code snippets into the file.
43+
## Get Latest Block Number
6744

6845
<CodeGroup>
69-
```javascript Viem
70-
import { createPublicClient, http } from 'viem'
71-
import { polygon } from 'viem/chains'
72-
73-
const client = createPublicClient({
74-
chain: polygon,
75-
transport: http('https://polygon-mainnet.g.alchemy.com/v2/demo') // Replace 'demo' with your API Key
76-
})
46+
```js
47+
const blockNumber = await client.getBlockNumber();
48+
console.log("Current block number:", blockNumber);
49+
```
50+
</CodeGroup>
7751

78-
async function main() {
79-
const latestBlock = await client.getBlockNumber()
80-
console.log('The latest block number is', latestBlock)
81-
}
52+
## Get an Address Balance
8253

83-
main()
84-
```
54+
<CodeGroup>
55+
```js
56+
const balance = await client.getBalance({ address: "0xab5801a7d398351b8be11c439e05c5b3259aec9b" });
57+
console.log("Balance (ETH):", Number(balance) / 1e18);
58+
```
59+
</CodeGroup>
8560

86-
```javascript Ethers.js
87-
import { JsonRpcProvider } from 'ethers'
61+
## Read Block Data
8862

89-
const provider = new JsonRpcProvider('https://polygon-mainnet.g.alchemy.com/v2/demo') // Replace 'demo' with your API Key
63+
<CodeGroup>
64+
```js
65+
const block = await client.getBlock({
66+
blockNumber: blockNumber, // from previous example
67+
});
68+
console.log(block);
69+
```
70+
</CodeGroup>
9071

91-
async function main() {
92-
const latestBlock = await provider.getBlockNumber()
93-
console.log('The latest block number is', latestBlock)
94-
}
72+
## Fetch a Transaction by Hash
9573

96-
main()
97-
```
74+
<CodeGroup>
75+
```js
76+
const tx = await client.getTransaction({ hash: "0xYOUR_TX_HASH" });
77+
console.log(tx);
78+
```
9879
</CodeGroup>
9980

100-
## 5. Run script
101-
102-
To run the above node script, use cmd `node index.js`, and you should see the output.
81+
## Fetch Transaction Receipt
10382

10483
<CodeGroup>
105-
```text shell
106-
The latest block number is 62250231n
107-
```
84+
```js
85+
const receipt = await client.getTransactionReceipt({
86+
hash: "0xYOUR_TX_HASH"
87+
});
88+
console.log(receipt);
89+
```
10890
</CodeGroup>
10991

110-
***
111-
11292
# Polygon Tutorials
11393

114-
You must not stop here! Want to build your first Dapp on Polygon and use Polygon APIs?
94+
Want to build your first Dapp on Polygon and use Polygon APIs?
11595

11696
Check out the following tutorials to learn how to build on Polygon:
11797

fern/docs.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ navigation:
790790
path: api-reference/data/nft-api/nft-api-overview.mdx
791791
- page: NFT API Quickstart
792792
path: api-reference/data/nft-api/nft-api-quickstart.mdx
793-
- section: Solana DAS APIs
793+
- section: Solana DAS API
794794
path: >-
795795
api-reference/data/nft-api/alchemy-das-apis-for-solana.mdx
796796
contents:
@@ -806,26 +806,6 @@ navigation:
806806
slug: nft-api-endpoints
807807
- page: NFT API FAQ
808808
path: api-reference/data/nft-api/nft-api-faq.mdx
809-
# - section: NFT API Tutorials
810-
# contents:
811-
# - page: How to Create NFT Token-Gated Communities
812-
# path: >-
813-
# tutorials/nfts/creating-nft-allowlists/how-to-create-nft-token-gated-communities-with-the-alchemy-nft-api.mdx
814-
# - page: How to Filter Out Spam NFTs
815-
# path: >-
816-
# tutorials/nfts/nft-api-tutorials/how-to-filter-out-spam-nfts.mdx
817-
# - page: How to Get NFT Owners at Specific Block
818-
# path: >-
819-
# tutorials/nfts/nft-api-tutorials/how-to-get-nft-owners-at-a-specific-block-height.mdx
820-
# - page: How to Get All NFTs Owned by Address
821-
# path: >-
822-
# tutorials/nfts/nft-api-tutorials/how-to-get-all-nfts-owned-by-an-address.mdx
823-
# - page: How to Get a List of NFT Holders for a Given Collection
824-
# path: >-
825-
# tutorials/nfts/nft-api-tutorials/how-to-get-a-list-of-nft-holders-for-a-given-collection.mdx
826-
# - page: How to Resolve ENS Domains Given a Wallet Address
827-
# path: >-
828-
# tutorials/nfts/nft-api-tutorials/how-to-resolve-ens-domains-given-a-wallet-address.mdx
829809
slug: nft-api-tutorials
830810
slug: nft-api
831811
- section: Webhooks
@@ -1061,14 +1041,8 @@ navigation:
10611041
slug: solana
10621042
- section: Polygon PoS
10631043
contents:
1064-
- section: Polygon PoS API Quickstart
1065-
path: >-
1066-
api-reference/polygon-pos/polygon-api-quickstart.mdx
1067-
contents:
1068-
- page: Polygon SDK Examples
1069-
path: >-
1070-
api-reference/polygon-pos/polygon-pos-api-quickstart/polygon-sdk-examples.mdx
1071-
slug: polygon-pos-api-quickstart
1044+
- page: Polygon PoS API Quickstart
1045+
path: api-reference/polygon-pos/polygon-api-quickstart.mdx
10721046
- page: Polygon PoS API FAQ
10731047
path: api-reference/polygon-pos/polygon-api-faq.mdx
10741048
- api: Polygon POS API Endpoints

0 commit comments

Comments
 (0)