Watengenezaji wa Ethereum kwa kawaida hutegemea Infura au Alchemy kwa upatikanaji wa urahisi wa nodes za Ethereum. GetBlock ni chaguo la kuvutia ambalo hutoa msaada wa multi-chain, ngazi ya bure ya bure, na utulivu mzuri. Katika mwongozo huu, utajifunza jinsi ya kuhamisha backend ya Truffle + web3.js kutoka Infura / Alchemy hadi GetBlock. Nitafunza kwa haraka kwa nini unapaswa kubadilisha wauzaji na kisha maelezo ya kila hatua: Kujiandikisha kwa GetBlock, Kupata mwelekeo wa RPC, kurejesha mfumo wa truffle, Utafiti wa Uunganisho wa Web3, running deployments, and kulinganisha kiwango cha riba na kufuatilia tofauti. Unahitaji mradi wa sasa wa Ethereum DApp na Truffle, na Node.js imewekwa. Nadhani umekuwa unatumia Infura au Alchemy (na ID ya mradi au API key) na kuwa na key mnemonic au binafsi inapatikana kwa utekelezaji. Prerequisites: Kwa nini kubadili kutoka Infura au Alchemy kwa GetBlock? GetBlock allows you to connect to not just Ethereum but 55+ blockchain networks using JSON-RPC, REST, and WebSocket APIs. This allows you to use Ethereum, Bitcoin, BNB Smart Chain, Polygon, Solana, and a lot of others with one platform. Infura and Alchemy, meanwhile, have a shorter list of networks supported (Infura supports Ethereum primarily and some networks like IPFS or certain L2s, and Alchemy supports Ethereum and some chains but not BSC specifically). If your DApp can be more than Ethereum, the broad multi-chain support of GetBlock is a huge plus. Multi-chain support. Each of these providers has free plans, but their limitations and models are different. Infura's free plan conventionally provided around 50,000 requests per day (now measured as 3 million daily credits with some rate limiting). Alchemy's free tier offers up to 100 million compute units a month (Alchemy measures different RPC calls as different "compute units"). GetBlock's free tier is very developer-friendly: it offers 50,000 requests a day (reset daily) with a limit of 5 requests a second. Practically, 50k daily calls are sufficient for development and small DApps, and you can always upgrade in case you need more. The free plan is indeed free ("zero fees") and still allows access to all supported chains. The key takeaway here is that GetBlock's free plan should be more than sufficient for typical dev and testing demands. Generous free tier. GetBlock offers a 99.9% uptime guarantee with a stable 24/7 connection to blockchain networks. That is, you can expect a highly stable service for your DApp backend. Stability is also what Infura and Alchemy are famous for, but GetBlock's infrastructure is built to be rock-solid and scalable. Many developers appreciate the fact that GetBlock provides both shared nodes (with usage limits) and dedicated nodes for heavier workloads, so you have a way to scale up. The correct answer is that the platform is highly reliable, so you won't see variations in network uptime when you switch over – possibly except for better performance in certain instances. Stability and uptime. Hatimaye, dashboard ya GetBlock ina uwezo mzuri wa ufuatiliaji na uchambuzi, ambayo tutaweza kupata hivi karibuni. Hatua ya 1: Kujiandikisha kwa Akaunti ya GetBlock Hatua ya kwanza ni kujiandikisha kwa akaunti ya bure ya GetBlock: Navigate to the GetBlock website and click on "Sign Up" (or directly visit the GetBlock dashboard sign-up page). You have a few sign-up options: Email/Password. Sign up using email and choose a password. Social Login. Use Google or GitHub to sign up immediately. Web3 Wallet. You can even sign up by connecting a MetaMask wallet (no email required). This is a great option for developers who are already set up on MetaMask. Chagua njia yako iliyopenda na ufuate maelekezo (kwa mfano, kuthibitisha barua pepe yako ikiwa umechagua usajili wa barua pepe). Unapaswa kuwa na akaunti yako ya GetBlock ndani ya dakika moja au mbili. Kumbuka. Picha ya GetBlock ni mahali ambapo utashughulikia vituo vya mwisho vya API, ufuatiliaji wa matumizi, na mipangilio ya kurekebisha. Nenda mbele na kuangalia karibu baada ya kujiandikisha. Utakuwa na kuona ID yako ya mtumiaji kwenye mipangilio ya akaunti (na muhimu ikiwa unahitaji msaada), lakini muhimu zaidi, utakuwa kuanzisha vituo vya mwisho wa mradi baadaye. Hatua ya 2: Kupata GetBlock yako RPC Endpoint (API Key na URL) Akaunti iliyoundwa, sasa utahitaji kuunda kiungo cha RPC kwa mtandao wa Ethereum (au mtandao wowote unachohitaji). Hii itakupa URL ya HTTP (na URL ya WebSocket inayohusiana ikiwa inahitajika) ambayo utaitumia badala ya Infura / Alchemy. Kuanzisha sehemu mpya ya mwisho: Katika GetBlock Dashboard, angalia kifungo cha "Tengeneza Endpoint" au "Tengeneza Endpoint Mpya". Select the blockchain network. As in our case, choose Ethereum from the list of available protocols. Then select the network type: For Ethereum Mainnet, choose Mainnet. For a testnet, choose the specific test network (GetBlock now supports Ethereum Sepolia). Kwa chaguo, kutoa jina / alama kwa kiungo hiki (kwa mfano, "MyDApp Ethereum Mainnet") ili iwe rahisi kwako kufuatilia ikiwa unatengeneza kiungo kimoja zaidi. Bonyeza kuunda au kuthibitisha. dashboard itaunda maelezo yako ya kiwango cha mwisho. Baada ya kuunda, unapaswa kuona URL ya RPC kwa kiwango chako cha mwisho. Inapaswa kuonekana kama: Copy URL hii; utakuwa kupitisha kwenye Truffle config yako. GetBlock inaweza kuonyesha URL ya WebSocket (kuanza na wss://) kwa mwisho huo, na wakati maombi yako inahitaji WebSockets (kwa usajili au matukio ya moja kwa moja), unaweza kutumia hiyo. Kuhifadhi GetBlock API key yako salama. Usifanye kuwa repo ya umma au msimbo wa upande wa mteja. Mafunzo bora ni kuhifadhi kama variable ya mazingira au config faili nje ya udhibiti wa chanzo. Nitaonyesha na variables ya mazingira katika hatua inayofuata. ya muhimu. Sasa una URL ya mwisho ya GetBlock na kifungo cha API, tayari kutumia. Sasa, hebu tuingize kwenye Truffle. Hatua ya 3: Badilisha muundo wa Truffle kutumia GetBlock yako ya (au ya katika matoleo ya zamani) ni mahali ambapo unatengeneza mipangilio ya mtandao. Ikiwa unatumia Infura au Alchemy, config yako inaweza kuwa kama hii kwa mtandao: truffle-config.js truffle.js require('dotenv').config(); const HDWalletProvider = require('@truffle/hdwallet-provider'); const INFURA_PROJECT_ID = process.env.INFURA_PROJECT_ID; const MNEMONIC = process.env.MNEMONIC; // or a private key module.exports = { networks: { ropsten: { provider: () => new HDWalletProvider(MNEMONIC, `https://ropsten.infura.io/v3/${INFURA_PROJECT_ID}`), network_id: 3, gas: 5500000, confirmations: 2, timeoutBlocks: 200, skipDryRun: true }, // ... other networks ... }, // ... other Truffle config ... }; Lengo letu ni kubadilisha URL ya Infura na URL ya GetBlock (na sawa kwa URL yoyote ya Alchemy). Habari njema ni kwamba RPC ya GetBlock inafanya kazi kwa njia sawa - unatoa URL ya mwisho na mtoa huduma wako wa wallet. Ikiwa mradi wako wa Truffle haujawahi kutumia (Ni uwezekano, ikiwa umewekwa kupitia Infura / Alchemy), kufunga na Maktaba hii inaruhusu Truffle kuandika shughuli na vifungo vyako na kuwasilisha kupitia node ya mbali. Kuanza kwa HDWalletProvider. @truffle/hdwallet-provider npm install @truffle/hdwallet-provider mabadiliko ya Ongeza GetBlock API yako kwenye variables yako ya mazingira (kwa mfano, katika Faili ya set Pia uhakikishe kwamba kifungo chako cha mnemonic au kibinafsi ni katika env var (kwa mfano, au Kwa mfano, kutumia Ethereum Sepolia testnet kupitia GetBlock: truffle-config.js .env GETBLOCK_API_KEY=<your_key_here> MNEMONIC PRIVATE_KEY require('dotenv').config(); const HDWalletProvider = require('@truffle/hdwallet-provider'); const PRIVATE_KEY = process.env.PRIVATE_KEY; // your wallet private key (hex string, no 0x) const GETBLOCK_KEY = process.env.GETBLOCK_API_KEY; // your GetBlock API key module.exports = { networks: { sepolia: { provider: () => new HDWalletProvider( PRIVATE_KEY, `https://eth.getblock.io/sepolia/?api_key=${GETBLOCK_KEY}` ), network_id: 11155111, // Sepolia network ID gas: 5500000, // Gas limit, adjust as needed confirmations: 2, // # of blocks to wait between deployments (optional) timeoutBlocks: 200, // # of blocks before a deployment times out (optional) skipDryRun: true // Skip dry run before migrations (recommended for public nets) }, // ... other networks (mainnet, etc) ... }, // ... rest of config ... }; Mabadiliko muhimu ni URL: tulitumia Kwa upande wetu Picha hii ilipigwa tokea ktk veranda za moja ya vyumba vya Manyara Serena Lodge. mtandao, itakuwa njia kupitia GetBlock badala ya Infura. Ikiwa unataka kuunda Mainnet, unaweza kuongeza sehemu sawa: https://eth.getblock.io/... ?api_key= sepolia mainnet: { provider: () => new HDWalletProvider( PRIVATE_KEY, `https://eth.getblock.io/mainnet/?api_key=${GETBLOCK_KEY}` ), network_id: 1, gas: 5500000, gasPrice: 20e9, // e.g., 20 Gwei (you may adjust according to network conditions) confirmations: 2, timeoutBlocks: 200, skipDryRun: true } Kuwa na uhakika wa kubadilisha kwa sahihi kwa mtandao wako (mainnet ya Ethereum ni 1, Sepolia ni 11155111, nk.). network_id ya ni nini matumizi hapa, lakini GetBlock pia inasaidia kuingiza kichwa katika njia (kama unaweza kuona katika mifano fulani). Wote wawili ni sawa. Ni kawaida zaidi kutumia parameter query na ni rahisi kushughulikia templates string. Maelezo ya. https://eth.getblock.io/<network>/?api_key=.. Hatua ya 4: Kuweka na kujaribu web3.js na GetBlock Kabla ya kutuma mikataba yako nje, ni wazo nzuri kuangalia kwamba kila kitu ni iliyoundwa vizuri. Unaweza kufanya hivyo kwa njia kadhaa: Truffle Console. Run (or the name of the network you specified). This will launch a console with Web3 available interactively. Try running something as a test, such as this: . If everything is properly set up, this should display the current block number on that network via GetBlock. If you get a response, your connection is solid! truffle console --network sepolia await web3.eth.getBlockNumber() Node.js Script. Alternatively, you could test using web3.js in a standalone script. First, make sure you have web3 installed ( ), then create a simple script like below to get the latest block number: npm install web3 // test-getblock.js const Web3 = require('web3'); const RPC_URL = `https://eth.getblock.io/sepolia/?api_key=${process.env.GETBLOCK_API_KEY}`; const web3 = new Web3(RPC_URL); web3.eth.getBlockNumber() .then(num => console.log("Latest block number:", num)) .catch(err => console.error("Error connecting to GetBlock:", err)); Usisahau kupakia variables yako ya mazingira (unaweza kuongeza juu na kufafanua GETBLOCK_API_KEY katika .env yako). Ikiwa inafichua nambari ya mstari, umeunganishwa kwa ufanisi na GetBlock kupitia web3.js. require('dotenv').config(); node test-getblock.js Utafiti wa juu unatumia wito rahisi wa kusoma ( Unaweza kujaribu zaidi, kama vile kutafuta block au hesabu ya akaunti, ili kuthibitisha zaidi mambo yanafanya kazi. Kwa mfano: eth_getBlockNumber const latestBlock = await web3.eth.getBlock('latest'); console.log("Latest block info:", latestBlock); Maombi haya yote yanapita kupitia node ya GetBlock. Ikiwa kuna kitu kibaya (kwa mfano, unapata makosa ya utambulisho), angalia kifungo chako cha API katika URL ni sahihi na kikomo cha bure cha akaunti yako hayakupungukiwa (hakuna uwezekano mkubwa kwa maombi machache tu). Ikiwa umewahi kutumia mtoa huduma wa Alchemy au Infura wa web3 katika msimbo (yaani, Alchemy inatoa mteja wa Web3 au SDK na mbinu za kibinafsi), kubadilisha kwa GetBlock ita maana utaendelea kutumia mbinu za msingi za Web3. kwa ajili ya tip. Hatua ya 5: Kuendesha Uhamiaji wa Truffle na Majaribio kwenye GetBlock Na hatimaye, mtihani halisi - kutekeleza mikataba yako na mwenyeji wa DApp yako na GetBlock kama mtoa huduma wako wa backend. Kuanzisha mikataba kwa kawaida na Truffle, lakini ametoa mwongozo wa kutumikia kwenye mtandao uliyoweka kwa GetBlock. Kwa mfano: Utekelezaji wa mikataba. truffle migrate --network sepolia Truffle itajumuisha mikataba yako (ikiwa hayakujumuishwa tayari) na kisha kutumia HDWalletProvider kuhamisha shughuli za utekelezaji kwenye RPC ya GetBlock. Unapaswa kuwa na uwezo wa kutazama output katika console ya mikataba iliyotumwa, uthibitisho unaopatikana, nk Mchakato ni sawa kama ilivyokuwa na Infura / Alchemy - tofauti pekee nyuma ya matukio ni URL ya node. Wakati wa kupanua kwenye Ethereum mainnet, hakikisha una kiasi sahihi cha ETH inapatikana katika akaunti yako ya mtumiaji na usikilize bei ya gesi. amri ya uhamisho itakuwa (Kwa kufanya kazi yako Uzoefu unapaswa kuwa sawa na wa Infura: GetBlock ni tu kuhamisha shughuli zako zilizosajiliwa kwenye mtandao wa Ethereum. truffle migrate --network mainnet mainnet Ikiwa una mtihani wa Truffle au vitabu ambavyo vinasema mikataba yako, unaweza kujaribu kwenye mtandao unaotolewa na GetBlock pia: Majaribio ya kuendesha. truffle test --network sepolia Hii itaendesha mkusanyiko wako wa majaribio kwenye hatua ya mwisho ya GetBlock. shughuli za majaribio (kwa mfano, wito wa kazi ya mkataba kwenye mikataba yako iliyotumika) zitapelekwa juu ya node ya GetBlock. Pamoja na matukio machache, RPC endpoint switching haipaswi kuathiri tabia ya Ethereum. Ikiwa uhamiaji wako au majaribio yalitendeka vizuri kwenye Infura / Alchemy, wanapaswa kuendesha vizuri kwenye GetBlock. Wito wote wa default JSON-RPC hutumika kwa GetBlock (kwa mfano, kupeleka mikataba, kusoma hali, kutuma shughuli, maswali ya matukio) - ni huduma kamili ya node. Ikiwa wito wa JSON-RPC umefutwa kwa sababu yoyote, dosari za GetBlock kwa kawaida zinaonyesha hivyo, lakini wito rahisi kama kupeleka ( Maoni yako ( ), kupokea mapato, nk, wote inapatikana. tabia ya kutarajia. eth_sendRawTransaction eth_call Congratulations! backend yako ya DApp ni sasa kwenye GetBlock! uhamiaji wako umefanyika. wito wako wa web3 unatumia miundombinu ya GetBlock na mikataba yako ya smart ni ya kuishi. Utaratibu wa API, viwango vya kikomo, na ufuatiliaji kwenye GetBlock Mabadiliko ya watoa huduma sio tu suala la update URLs - pia ni muhimu kujua kama kuna tofauti katika jinsi matumizi ni kufuatiliwa pamoja na kufuatilia utendaji wa DApp yako juu ya watoa huduma mpya. Infura alitumia ID ya mradi katika URL; Alchemy alitumia kifungo cha API mara nyingi zaidi katika fomu iliyoingizwa katika URL pia (au kikoa cha kibinafsi). Njia ya GetBlock pia ni sawa - utakuwa na token ya upatikanaji (kifungo cha API) na utaongeza hii kwenye URL ya RPC. Katika ngazi ya kazi, maombi yako haina haja ya kufanya kifungo chako kufanya kitu chochote cha kawaida isipokuwa kuingiza kwenye URL ya mwisho. Vivyo hivyo, kama umekuwa na infura Project ID yako au kifungo cha API cha Alchemy, uhakikishe kifungo cha GetBlock (kuhifadhi katika variable ya mazingira, sio msimbo wa upande wa mteja). Mifumo ya API Key Setup Kuna mipaka ya kila mtoa huduma kwenye ngazi ya bure: Mabadiliko ya kiwango na upatikanaji. GetBlock Free Tier. 50,000 compute units per day and max 5 requests per second. In practice, 1 simple RPC call ≈ 1 CU (more complex calls like logs could be more counted, as with Alchemy's system). The 5 RPS restriction will make you not burst more than 5 requests in the same second on free tier. If so, subsequent calls may be refused with a rate-limit response. For all but the most busy DApps, 5 RPS is fine while developing – but if your backend scripts are making lots of concurrent calls, you may need to rate-limit them or consider switching to a more expensive plan (the one after this offers 25 RPS). Infura. Infura's free tier was circa 100k requests/day historically and since their new configuration, it's 6 million credits/day throughput of up to 2,000 credits/sec (which is roughly the equivalent of perhaps ~2000 simple calls/sec). Infura's generous free plan RPS is very kind, but note the fact that not all calls are 1 credit (some big calls are more credits). Either way, if your DApp wasn't hitting Infura's limits, it likely won't hit GetBlock's either, by similar scale. Alchemy. Alchemy's 100M free tier monthly of compute units is significant as well. They have no hard RPS fee, but intense usage will consume those compute units quickly. Alchemy bills calls (e.g., a simple ETH call might be 0.5 CU, a complex one 10 CUs, etc.). If you weren’t close to 100M units, you should be fine switching to 50k/day (≈1.5M/month) on GetBlock for dev. If 50k/day is not enough (e.g., if you are running a production app on a free plan – not typical), you might have to move to GetBlock's paid plans which offer much higher monthly CUs. Kipengele kingine cha kushangaza cha GetBlock ni dashboard yake na uchambuzi kamili. Kwenye ukurasa wa msingi wa dashboard yako, unapata maelezo ya jumla ya mpango wako wa sasa, CUs zilizopo kwa siku, kiwango cha RPS yako ya sasa, na maombi ya jumla yaliyotolewa katika masaa ya 24 iliyopita. Hii inakuwezesha kujua mara moja ikiwa unapata kiwango chako cha kila siku. Zaidi ya hayo, kwenye kifungo cha "Statistiki" au "Analytics" cha pointi zako za mwisho, GetBlock hutoa chati na upungufu wa: Ufuatiliaji wa matumizi. Idadi ya maombi kwa muda Response statuses (so you can see if there were any errors) Usambazaji wa njia ya wito (ambayo RPC mbinu wewe ni wito zaidi) Ukiukwaji wowote wa kikomo cha kiwango (ikiwa umepiga kikomo cha RPS) Ufuatiliaji wa takwimu hizi ni ilipendekezwa sana, hasa wakati unapokuwa kwenye mabadiliko. Kwa mfano, ikiwa umesoma script kwa makosa ambayo inapanda mtandao na wito, orodha itaonyesha ongezeko la idadi ya maombi au hata majibu ya kiwango cha kiwango cha 429. Hili ni mahali ambapo ungependa kuboresha wito wako wa nyuma wa DApp. Infura na Alchemy pia hutoa boards, lakini faida ya GetBlock ni kwamba unaweza kufuatilia matumizi yako yote ya multi-chain kutoka mahali moja. Ikiwa mpango wa bure sio wa kutosha (kwamba programu yako inaweza kupanua), GetBlock ina upgrades rahisi - mpango wa Starter (~50M CUs / mwezi, ~1.6M / siku, 25 RPS) na mpango wa Pro (600M / mwezi, 200 RPS). Unaweza kuboresha moja kwa moja kutoka kwenye dashboard. Lakini wakati wa maendeleo, huenda hautahitaji hili. Pia kumbuka kwamba CUs za kila siku zisizotumika katika mpango wa bure hazijapelekwa (wanapanga kila siku), hivyo haina thamani ya kuokoa wito - tu kutumia kile unachohitaji. mipaka ya utekelezaji. Mpango wa bure wa GetBlock unajumuisha msaada wa tokens za upatikanaji hadi 2 (endpoints). Hiyo inamaanisha unaweza kuunda moja kwa mainnet, moja kwa testnet, yaani – kuweka miradi yako au mazingira ya kujitenga. Kila kiini cha mwisho kitakuwa na kichwa chake cha API na kufuatilia matumizi. Hii ni sawa na mbinu ya "Project ID kwa mradi" ya Infura. Ni mazoezi mazuri ya kuwa na vituo vya mwisho tofauti kwa ajili ya maendeleo na uzalishaji ili uweze kufuatilia matumizi kwa kujitegemea. Baadhi ya vitu vya mwisho. Mazoezi bora kwa uhamiaji usio na ufanisi Hapa ni kile ninachokipendekeza kwako: Maintain environment variables. Place your API keys and secrets (mnemonic/private key) in an file or in your system environment, not in source code. This makes switching endpoints easier and more secure. .env Test on a testnet first. While switching providers, attempt to deploy on a test network (Sepolia) with the help of GetBlock before working on mainnet. This makes sure that your setup is right. After confirmation, you can shift your mainnet setup. Compare behavior. It is a good idea to do some sanity checks after migration – i.e., get a known contract's data via Infura and via GetBlock and compare that the results are identical. They should be, since both are reading from Ethereum, but this can give confidence that GetBlock is in full sync (GetBlock does run full nodes, so it should be). WebSockets (if required). If your backend relies on WebSocket subscriptions (i.e., listening to events), GetBlock does offer that too. Simply use the URL in a Web3 WebsocketProvider. Ensure that your plan covers the throughput your subscriptions require (the same RPS limits apply to websockets). The majority of developers, however, use WebSockets in the frontend (with a library like MetaMask or Alchemy's subscription API). In purely backend contexts, WebSockets are less common, but it’s good to know GetBlock has the option. wss://go.getblock.io/xxxxxxx No frontend changes. Since this migration is backend-facing, your frontend (if you have one) doesn't have to change. If you were using MetaMask to connect to a testnet using Infura, you can still do so – MetaMask does not require GetBlock for connecting users (though GetBlock can also provide custom RPC endpoints for MetaMask). The separation of concerns (frontend vs. backend) remains. Mwisho wa Kwa kufuata mwongozo huu, sasa umepita backend yako ya Ethereum DApp kutoka Infura / Alchemy hadi GetBlock. Muundo wako wa Truffle sasa unaonyesha RPC ya GetBlock, na unaweza kutumia mikataba na kufanya wito wa web3.js kupitia GetBlock kwa njia sawa kama ulivyoweza kabla. Uhamiaji haitabadilisha kazi ya DApp yako, hata hivyo inakuwezesha kuongeza blockchains ziada au kuongeza matumizi bila kuendesha nodes yako mwenyewe.