Skip to content

Commit 7a981da

Browse files
committed
Update PoS - reorg
1 parent bb365b2 commit 7a981da

26 files changed

+5248
-0
lines changed

docs/pos/run-node/access-node.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
If you're a new Web3 developer, it's unlikely that you'll need to run your own full node on Polygon.
2+
3+
The majority of developers use a node provider, or a third-party external service that receives node requests and returns responses for you automatically. That's because the fastest way to get developing on Polygon is using a node provider rather than managing your own node.
4+
5+
!!! tip Recommended
6+
7+
New developers on the Polygon network can use Alchemy as their node provider because of its reliability, scalability, and [Enhanced APIs](https://docs.alchemy.com/reference/enhanced-apis-overview).
8+
9+
## Send your first blockchain request
10+
11+
This guide assumes you already have an [Alchemy account](https://alchemy.com/?r=e68b2f77-7fc7-4ef7-8e9c-cdfea869b9b5) and access to the [Alchemy Dashboard](https://dashboard.alchemyapi.io).
12+
13+
### Create an Alchemy Key
14+
15+
First, you'll need an Alchemy API key to authenticate your requests. You can [create API keys from the dashboard](http://dashboard.alchemyapi.io). Check out [this YouTube video](https://www.youtube.com/watch?v=tfggWxfG9o0) on how to create an app. Or you can follow the steps written below:
16+
17+
**Step 1 →** Navigate to the **Create App** button in the **Apps** tab.
18+
19+
![img](https://files.readme.io/693457a-Getting_Started.png)
20+
21+
**Step 2 →** Fill in the details under **Create App** to get your new key. You can also see the applications you previously made by you and your team on this page. Pull existing keys by clicking on **View Key** for any app.
22+
23+
![img](https://files.readme.io/d6172a5-Create_App_Details.png)
24+
25+
**Optional →** You can also pull existing API keys by hovering over **Apps** and selecting one. You can **View Key** here, as well as **Edit App** to whitelist specific domains, see several developer tools, and view analytics.
26+
27+
![img](https://files.readme.io/f0dbb19-ezgif.com-gif-maker_1.gif)
28+
29+
### Making a cURL request
30+
31+
You can interact with Alchemy's Polygon infrastructure provider using JSON-RPC and your [command line interface](https://www.computerhope.com/jargon/c/commandi.htm).
32+
33+
For manual requests, we recommend interacting with the `JSON-RPC` via `POST` requests. Simply pass in the `Content-Type: application/json` header and your query as the `POST` body with the following fields:
34+
35+
* `jsonrpc`: The JSON-RPC version—currently, only `2.0` is supported.
36+
* `method`: The MATIC API method. [See API reference](https://alchemyenterprisegroup.readme.io/reference/polygon-api-quickstart).
37+
* `params`: A list of parameters to pass to the method.
38+
* `id`: The ID of your request. Will be returned by the response so you can keep track of which request a response belongs to.
39+
40+
Here is an example you can run from the Terminal/Windows/LINUX command line to retrieve the current gas price:
41+
42+
```bash
43+
curl https://matic-mainnet.alchemyapi.io/v2/demo \
44+
-X POST \
45+
-H "Content-Type: application/json" \
46+
-d '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":73}'
47+
```
48+
49+
!!! info
50+
51+
In case you want to send requests to your own app instead of our public demo, replace `https://eth-mainnet.alchemyapi.io/jsonrpc/demo` with your own API key `https://eth-mainnet.alchemyapi.io/v2/your-api-key`.
52+
53+
Results:
54+
55+
```json
56+
{ "id": 73,
57+
"jsonrpc": "2.0",
58+
"result": "0x09184e72a000" // 10000000000000 }
59+
```
60+
61+
## Alchemy SDK setup
62+
63+
To make blockchain requests directly from your Javascript / Node.js dApp, you'll need to integrate the **Alchemy SDK**, the easiest and most powerful way to access the blockchain and Alchemy's suite of enhanced APIs.
64+
65+
**If you have an existing client such as Web3.js or Ethers.js,** you can just change your current node provider URL to an Alchemy URL with your API key: <https://eth-mainnet.alchemyapi.io/v2/your-api-key>
66+
67+
!!! note
68+
69+
The scripts below need to be run in a **node context** or **saved in a file**, not run from the command line.
70+
71+
### Install the Alchemy SDK
72+
73+
To install the Alchemy SDK, you want to create a project, and then navigate to your project directory to run the installation. Let's go ahead and do that! Once we're in our home directory, let's execute the following:
74+
75+
With Yarn:
76+
77+
```bash
78+
mkdir your-project-name
79+
cd your-project-name
80+
yarn init # (or yarn init --yes)
81+
yarn add alchemy-sdk
82+
```
83+
84+
With NPM:
85+
86+
```bash
87+
mkdir your-project-name
88+
cd your-project-name
89+
npm init # (or npm init --yes)
90+
npm install alchemy-sdk
91+
```
92+
93+
### Create `index.js`
94+
95+
Make sure to replace `demo` with your Alchemy HTTP API key!
96+
97+
```js title="index.js"
98+
// Setup: npm install alchemy-sdk
99+
const { Network, Alchemy } = require("alchemy-sdk");
100+
101+
// Optional Config object, but defaults to demo api-key and eth-mainnet.
102+
const settings = {
103+
apiKey: "demo", // Replace with your Alchemy API Key.
104+
network: Network.MATIC_MAINNET, // Replace with your network.
105+
};
106+
107+
const alchemy = new Alchemy(settings);
108+
109+
async function main() {
110+
const latestBlock = await alchemy.core.getBlockNumber();
111+
console.log("The latest block number is", latestBlock);
112+
}
113+
114+
main();
115+
```
116+
117+
If you are unfamiliar with the async stuff, check out this [Medium post](https://betterprogramming.pub/understanding-async-await-in-javascript-1d81bb079b2c).
118+
119+
### Run `index.js` using node.js
120+
121+
```bash
122+
node index.js
123+
```
124+
125+
### Console output
126+
127+
You should now see the latest block number output in your console.
128+
129+
```bash
130+
The latest block number is 11043912
131+
```
132+
133+
**Excellent! You just wrote a working Web3 script and sent your first request to your Alchemy API endpoint.**
134+
135+
The project associated with your API key should now look like this on the dashboard:
136+
137+
![img](https://files.readme.io/e3d2ffd-Alchemy_Tutorial_Result1.png)
138+
139+
![img](https://files.readme.io/bcfc9ff-Alchemy_Tutorial_Result2.png)
140+
141+
## Start building
142+
143+
Don't know where to start? Check out these tutorials to get more familiar with Alchemy and blockchain development:
144+
145+
1. [Examples of Common Queries Using the Alchemy SDK](https://docs.alchemy.com/reference/using-the-alchemy-sdk)
146+
3. Learn [How to Send Transactions on Ethereum](https://docs.alchemy.com/docs/how-to-send-transactions-on-ethereum)
147+
4. Try deploying your first [Hello World Smart Contract](https://docs.alchemy.com/docs/hello-world-smart-contract) and get your hands dirty with some solidity programming!
148+
149+
### Other Web3 libraries
150+
151+
There are a number of alternative Web3 libraries other than the Alchemy SDK you may already be using. See the documentation for these libraries below:
152+
153+
* [Web3.py](https://web3py.readthedocs.io/en/stable/)
154+
* [Web3j](https://docs.web3j.io)
155+
* [Ethers.js](https://docs.ethers.io/v5/)
156+
* [Web3.js](https://web3js.readthedocs.io/en/v1.2.9/)
157+
158+
Using the below code snippets, you can install and use Alchemy as a provider via any of the following libraries.
159+
160+
```python
161+
# Setup: pip install web3
162+
from web3 import Web3
163+
alchemy = Web3(Web3.HTTPProvider("https://eth-mainnet.alchemyapi.io/v2/your-api-key"));
164+
```
165+
166+
```js
167+
// Setup: curl -L get.web3j.io | sh
168+
Web3j web3 = Web3j.build(new HttpService("https://eth-mainnet.alchemyapi.io/v2/your-api-key"));
169+
```
170+
171+
```js
172+
// Setup: npm install ethers
173+
const ethers = require("ethers");
174+
const url = "https://eth-mainnet.alchemyapi.io/v2/your-api-key";
175+
const customHttpProvider = new ethers.providers.JsonRpcProvider(url);
176+
```
177+
178+
```js
179+
// Setup: npm install web3
180+
const Web3 = require('web3');
181+
const web3 = new Web3("https://eth-mainnet.alchemyapi.io/v2/your-api-key");
182+
```
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
2+
# How to delegate
3+
4+
This is a step-by-step guide to help you become a delegator on the Polygon Network.
5+
6+
The only prerequisite is to have your MATIC tokens and ETH on the Ethereum mainnet address.
7+
8+
## Access the dashboard
9+
10+
1. In your wallet (e.g. MetaMask), choose the Ethereum mainnet.
11+
12+
![Figure: Choose ERTHh mainnet ](../../../img/pos/choose-eth-mainnet.png)
13+
14+
2. Log in to [Polygon Staking](https://staking.polygon.technology/).
15+
16+
3. Once you log in, you will see overall statistics along with the list of validators.
17+
18+
![img](../../../img/pos/home.png)
19+
20+
21+
22+
23+
!!!note
24+
If you are a validator, use a different non-validating address to log in as delegator.
25+
26+
27+
## Delegate to a validator
28+
29+
1. Click "Become a Delegator" or scroll down to a specific validator and click "Delegate".
30+
31+
![img](../../../img/pos/home.png)
32+
33+
2. Provide the amount of MATIC to delegate.
34+
35+
![img](../../../img/pos/delegateB.png)
36+
37+
38+
3. Approve the delegation transaction and click "Delegate".
39+
40+
![img](../../../img/pos/delegate2.png)
41+
42+
43+
After the delegation transaction completes, you will see the `Delegation Completed` message.
44+
45+
![img](../../../img/pos/delegate3.png)
46+
47+
48+
## View your delegations
49+
50+
To view your delegations, click "My Account".
51+
52+
![img](../../../img/pos/myAccount.png)
53+
54+
## Withdraw rewards
55+
56+
1. Click "My Account".
57+
58+
![img](../../../img/pos/click-my-account.png)
59+
60+
61+
2. Under your delegated validator, click "Withdraw Rewards".
62+
63+
![img](../../../img/pos/withdraw-reward.png)
64+
65+
66+
This will withdraw the MATIC token rewards to your Ethereum address.
67+
68+
## Restake rewards
69+
70+
1. Click "My Account".
71+
72+
![img](../../../img/pos/click-my-account.png)
73+
74+
75+
2. Under your delegated validator, click "Restake Reward".
76+
77+
![img](../../../img/pos/restake-rewards.png)
78+
79+
80+
81+
This will restake the MATIC token rewards to the validator and increase your delegation stake.
82+
83+
## Unbond from a validator
84+
85+
1. Click "My Account".
86+
87+
![img](../../../img/pos/click-my-account.png)
88+
89+
90+
2. Under your delegated validator, click "Unbond".
91+
92+
![img](../../../img/pos/unbond-from-validator.png)
93+
94+
95+
This will withdraw your rewards from the validator and your entire stake from the validator.
96+
97+
Your withdrawn rewards will show up immediately on your Ethereum account.
98+
99+
Your withdrawn stake funds will be locked for 80 checkpoints.
100+
101+
![img](../../../img/pos/unbond.png)
102+
103+
104+
!!!note
105+
106+
The fund locking for the unbonding period is in place to ensure there is no malicious behaviour on the network.
107+
108+
109+
## Move stake from one node to another node
110+
111+
Moving stake from one node to another node is a single transaction. There are no delays or unbonding periods during this event.
112+
113+
1. Log in to the "My Account" on the Staking dashboard.
114+
115+
2. Click "Move Stake" under your delegated validator.
116+
117+
3. Select an external validator and click "Stake here".
118+
119+
![img](../../../img/pos/move.png)
120+
121+
122+
4. Provide the stake amount and click "Move Stake".
123+
124+
![img](../../../img/pos/move2.png)
125+
126+
127+
This will move the stake. The dashboard will update after 12 block confirmations.

0 commit comments

Comments
 (0)