RPC URLS: DAPP -Blockchain Bridge
When DAPP (decentralized) talks to Blockchain looks like ETHEREUM, it does this using the Json-RPC interface. In its essence, the URL RPC address is the web address of the JSON-RPC end point. It is the URL for server (usually HTTPS) calls for DAPP to recover data on the series or payment transactions.
For example, INTURA and Getblock are a common use services that give you URLs like https://mainnet.infura.io/v3/YOUR-API-KEY
or <https://go.getblock.io/<ACCESS-TOKEN>/>
. In the background, these URL addresses indicate a complete ETHEREUM knot that already reaches Blockchain. That is, your DAPP Web3 Library (ETHERS.JS, Web3.js, etc.) makes Json-RPC “remote procedure calls” through the URL to Blockchain. URL RPC is literally the network address to call the RPC end point in the Web3 environment.
Since it requests a mesh, you can (and must) choose a decent RPC provider. General end points such as Getblock or Cloudflare Ethereum Gateway allow you to call ETAREUM or EVM chains without the need for your node. For example, Quickstart’s intora display https://mainnet.infura.io/v3/<YOUR-API-KEY>
For ethereum Mainnet. The use of general RPCs (or your own knot) ensures that your DAPP is always able to read the latest blocs and send transactions.
Series’s identifiers: Find every network
The series ID is a unique number that defines a series compatible with EVM. Every network (Ethereum Mainnet, Polygon, Irbia, etc.) has a specific chain identifier, so know the transactions on the series they use. In practice, the chain identifier is baked in transactions signatures (after ethereum’s eip-155). This prevents the treatment of one chain from restarting it on another, although the headlines appear the same coordination on different chains. That is, by adding a chain identifier in the signed transaction, attacks are prevented from chains.
In Metamask’s network composition, you can manually provide the series and URL RPC. For example, the “Metamask Network” window contains the URL for the RPC and the series ID (digital identifier for use when signing transactions on the mentioned network). These two fields tell Metamask where you send your calls and any chain to sign in signatures. If you do not match the actual network, you will get errors or even signing transactions on the wrong series.
Series include the main networks:
- Ethereum Mainnet – ID Series 1
- Polygon (POS) – Series ID 137
- One definition – the series Identity 42161
- Main optimism – Series ID 10
- BNB Smart Chain – Chain ID 56
- Avalanche C-Chain-Chein ID 43114
All of these digital identifiers are used internally through the contract and the governor. For example, the Alchemy “Chain ID 1” series of ETAREUM and Chain ID 10 shows optimism, with their URLs RPC. When you switch or prepare networks, this identifier is how everyone knows what Blockchain is talking about.
Why this issue: the correct networks, safety and multi -technology support
The URL and the RPC letter is necessary to properly in any DAPP. The existence of the wrong RPC or the network identifier can make your application read the wrong data or even try to send transactions on the wrong Blockchain. As an explanation, the reference to the Polygon RPC but with the ETHEREUM series (or vice versa) will lead to a “wrong series ID ID” warning. Practically, the URL and RPC letter guarantees that DAPP speaks to the correct network.
Moreover, the series’s identifier is prohibited from transactions (according to EIP-155) signed transaction on a series of acceptance on another. This is the protection of restarting the way Ethereum does. Without the series ID, the transfer of ETHEREUM code will be played between, for example, ethereum classic or Sidechain with the same network address formats. With the series ID, each signature is connected to one network. It is important to track the user network series ID because all RPC requests are submitted to the current connected network. ”In practice, you must always bring DAPS chainId
(For example, across ethereum.request({ method: 'eth_chainId' })
) So that they can determine the network they are.
For DAPPS on multiple chains, this data is more important. An application like UISWAP will have to work on both ETAREUM and Polygon to modify URL RPC addresses and sign with the correct series ID whenever the user changes networks. metamask emits chainChanged
The event when the user changes networks, DAPS usually listens to it in order to download or re -create communications. In one word, the RPC end control and chain identifiers are the basis for safely connecting the front end to any Evm Blockchain.
How to use Metamask URL RPC addresses and chain identifiers
Metamask (and Anyman) Muxes URL RPC and series identifier together to set the network. When DAPP calls window.ethereum.request(…)
Metamask starts Json-RPC request to URL Set RPC. The series is used while signing messages and transactions. The metamask user interface already displays these fields when adding a network:
As this screen shot appears, it will be shown Metamask URL for a network and Chain Fields. URL for a network It is the URL address that Metamask will use to reach the network, and Chain It is the series of series that Metamask will use to sign the network transactions. In other words, once you agree to this dialog box, Metamask is known exactly the knot to be spoken to (via the URL RPC) and a chain indicating the signature signatures (via the series ID).
Software, DAPPS can inquire about the series ID and deal with network changes. Metamask developer guide recommends using eth_chainId
RPC method and listen to chainChanged
Take up to discover when the user replaces networks. For example, one may do:
const chainId = await ethereum.request({ method: 'eth_chainId' });
ethereum.on('chainChanged', (newChainId) => { window.location.reload(); });
This ensures that your code always knows the current chain identifier and re -calls if it changes. All this logic depends on the presence of the correct RPC and the series of the series that was formed in Metamask.
RPC joint points and chain identifiers
Here are some model networks and chain identifiers, for example the RPC URL addresses:
- Ethereum Mainnet – Series ID 1. General RPCs: Infura in
https://mainnet.infura.io/v3/YOUR-PROJECT-ID
Or Getblock inhttps://go.getblock.io/<your_access_token>
. (You must replaceYOUR-PROJECT-ID
/ /YOUR-ACESS-TOKEN
With your credentials.) - Polygon Pos – Series ID 137. RPC examples: for example
https://polygon-mainnet.infura.io/v3/YOUR-PROJECT-ID
Or Getblockhttps://go.getblock.io/<your_access_token>
- The one is one – Series ID 42161. Example RPC: Alchemy’s
https://arb-mainnet.g.alchemy.com/v2/YOUR-API-KEY
(Or generally arbitrary end points). - The main optimism – Series ID 10. Example RPC: Getblock
https://go.getblock.io/<your_access_token>
Or optimism officialhttps://mainnet.optimism.io
. - Smart BNB Series – Series Idrite 56. (RPC
https://bsc-dataseed.binance.org/
). - Avalanche C-Chain- Series Idrust 43114 (RPC
https://api.avax.network/ext/bc/C/rpc
).
Each of these networks can be added to wallets such as Metamask by providing URL RPC and chain ID. Like web sites Chain Collecting lists these details are checked for many networks – exactly the type of information metamask suggests you to check if something “does not match”.
Tips for allocated networks and local development
This is what I recommend:
- Check the network data. Repeat URL RPC and series ID versus official documents or community lists (EG Chainlist). Metamask has already reinforced the verification of the searched series of the series (seriesChainid.network) To check that it is true.
\
- Ten v Hex. Series ’identifiers can be determined in a decimal form (137) or Hex (0x89). Metamask is preferred to accept both but use both constantly. For example, Hardhat’s default chain is 1337 (0x539 Hex). If you modify one without modifying the other, Metamask will complain of incompatibility.
\
- Obtaining the local contract properly. For local DeV chains (Ganache, Hardhat, etc.), make sure that your knot chain identifier is identical to what has been formed for use. For example, if you are using the hypothetical Hardhat knot, you will find metamask on http://127.0.0.1:8545 With series ID 1337. Ganache users usually sees series ID 1337 or 5777; You can run Ganache with custom
--chainId
Knowledge is to match the haarah if necessary. Another chain identity that leads to the failure of Harrades.
\
- Manually switching networks in software instructions. Use
provider.getNetwork()
orethereum.request({method: 'eth_chainId'})
To seize the current chain definition at the time of operation. Listen to metamask’schainChanged
Event, re -download or reinstine your application when shoots. This makes your DAPP always knowing the network you communicate with after changing the user.
\
- Be careful not to restart attacks on the test. Upon testing on several chains (such as local Mainnet fork and Testnet), always sign transactions with the correct chain identifier. The series of the series in EIP-155 is what makes the treatment only valid for its destination chain, so choosing the wrong error would confuse your signature.
By assigning the URL and RPC chain ID carefully, you connect DAPP to the right Blockchain. This avoids micro -grain errors (such as sending distinctive symbols to the wrong network or leaving yourself open to restore attacks) and enable multi -smooth compatibility. In short, think about the URL RPC title as “i.e. knot” and the series identifier as “i.e. the world”-both of them are important contact information for any DAPP compatible with Ethereum.