Ethereum developers typically rely on Infura or Alchemy for easy access to Ethereum nodes. GetBlock is an attractive alternative that provides multi-chain support, a generous free tier, and excellent stability. In this tutorial, you'll discover how to migrate a Truffle + web3.js backend from Infura/Alchemy to GetBlock. I'll quickly cover why you should switch providers and then detail each step: ลงทะเบียนสําหรับ GetBlock รับจุดสิ้นสุด RPC การกําหนดค่าใหม่ของ Truffle การทดสอบการเชื่อมต่อ Web3 ดําเนินการการใช้งานและ การเปรียบเทียบขีด จํากัด และตรวจสอบความแตกต่าง คุณต้องการโครงการ Ethereum DApp ที่มีอยู่พร้อม Truffle และติดตั้ง Node.js ฉันคิดว่าคุณกําลังใช้ Infura หรือ Alchemy (พร้อม ID โครงการหรือคีย์ API) และมีคีย์ mnemonic หรือคีย์ส่วนตัวที่สามารถใช้งานได้ ลองเริ่มต้น! Prerequisites: ทําไมต้องเปลี่ยนจาก Infura หรือ Alchemy ไปยัง 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. สุดท้าย dashboard ของ GetBlock มีความสามารถในการตรวจสอบและวิเคราะห์ที่ยอดเยี่ยมซึ่งเราจะมาถึงเร็ว ๆ นี้ ตอนนี้เรามีเหตุผลให้เราจะดําเนินการกับวิธีการ ขั้นตอนที่ 1: ลงทะเบียนสําหรับบัญชี GetBlock ขั้นตอนแรกคือการลงทะเบียนสําหรับบัญชี 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. เลือกวิธีการที่คุณต้องการและดําเนินการตามคําแนะนํา (เช่นตรวจสอบอีเมลของคุณหากคุณเลือกการลงทะเบียนอีเมล) คุณควรมีบัญชี GetBlock ของคุณภายในนาทีหรือสองครั้ง เมื่อคุณเข้าสู่ระบบคุณจะถูกนําไปยัง GetBlock Dashboard หมายเหตุ แผงควบคุม GetBlock คือสถานที่ที่คุณจะจัดการกับจุดปลายทาง API ของคุณตรวจสอบการใช้งานและการปรับการตั้งค่า ลองไปข้างหน้าและมองรอบ ๆ เมื่อคุณลงทะเบียน คุณจะเห็น ID ผู้ใช้ของคุณในการตั้งค่าบัญชี (มีประโยชน์ถ้าคุณต้องการการสนับสนุน) แต่ที่สําคัญกว่านั้นคุณจะกําหนดค่าจุดปลายทางโครงการต่อไป ขั้นตอนที่ 2: Get Your GetBlock RPC Endpoint (API Key และ URL) บัญชีที่สร้างขึ้นตอนนี้คุณจะต้องสร้างจุดปลายทาง RPC สําหรับเครือข่าย Ethereum (หรือเครือข่ายใด ๆ ที่คุณต้องการ) นี้จะให้ URL HTTP (และ URL WebSocket ที่เกี่ยวข้องหากจําเป็น) ที่คุณจะใช้แทน Infura / Alchemy สร้างจุดสิ้นสุดใหม่: ใน GetBlock Dashboard ค้นหาปุ่ม "สร้าง Endpoint" หรือ "เพิ่ม Endpoint ใหม่" คลิกที่มันเพื่อเริ่มสร้างการเชื่อมต่อใหม่ 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). ตัวเลือกให้ชื่อ / แท็กสําหรับจุดสิ้นสุดนี้ (เช่น "MyDApp Ethereum Mainnet") เพื่อช่วยให้คุณสามารถติดตามได้ง่ายขึ้นในกรณีที่คุณกําหนดค่าจุดสิ้นสุดมากกว่าหนึ่งจุด คลิก สร้างหรือยืนยัน แผงควบคุมจะสร้างรายละเอียดของจุดสิ้นสุดของคุณ หลังจากสร้างคุณควรเห็น URL RPC สําหรับจุดสิ้นสุดของคุณ มันควรดูเหมือน: คัดลอก URL นี้; คุณจะผ่านไปยังการกําหนดค่า Truffle ของคุณ GetBlock สามารถแสดง URL WebSocket (เริ่มต้นด้วย wss://) สําหรับจุดสิ้นสุดเดียวกันและเมื่อแอปพลิเคชันของคุณต้องการ WebSockets (สําหรับการสมัครหรือกิจกรรมสด) คุณสามารถใช้ได้ ในบทเรียนของเราเราจะใช้จุดสิ้นสุด HTTP บันทึกคีย์ API GetBlock ของคุณได้อย่างปลอดภัย อย่าพึงประสงค์ให้เป็น repo สาธารณะหรือรหัสด้านลูกค้า การปฏิบัติที่ดีที่สุดคือการจัดเก็บเป็นตัวแปรสภาพแวดล้อมหรือกําหนดค่าไฟล์ภายนอกการควบคุมแหล่งที่มา ฉันจะแสดงด้วยตัวแปรสภาพแวดล้อมในขั้นตอนถัดไป ที่สําคัญ ตอนนี้คุณมี URL Endpoint GetBlock และคีย์ API พร้อมใช้งาน ตอนนี้ให้แทรกใน Truffle ขั้นตอนที่ 3: เปลี่ยนการกําหนดค่า Truffle เพื่อใช้ GetBlock ของคุณ (หรือ ในรุ่นเก่า) คือสถานที่ที่คุณกําหนดค่าการตั้งค่าเครือข่าย หากคุณใช้ Infura หรือ Alchemy การกําหนดค่าของคุณอาจมีลักษณะเช่นนี้สําหรับเครือข่าย: 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 ... }; วัตถุประสงค์ของเราคือการแทนที่ URL Infura กับ URL GetBlock (และคล้ายกันสําหรับ URL Alchemy) ข่าวดีคือ RPC ของ GetBlock ทํางานในลักษณะเดียวกัน - คุณให้ URL Endpoint และผู้ให้บริการกระเป๋าสตางค์ของคุณ หากโครงการ Truffle ของคุณยังไม่ได้ใช้ (เป็นไปได้ว่าถ้าคุณใช้งานผ่าน Infura / Alchemy) ติดตั้งด้วย แพคเกจนี้ช่วยให้ Truffle สามารถลงนามในธุรกรรมด้วยคีย์ของคุณและส่งผ่านศูนย์กลางระยะไกล ติดตั้ง HDWalletProvider @truffle/hdwallet-provider npm install @truffle/hdwallet-provider การเปลี่ยนแปลง เพิ่มคีย์ API GetBlock ไปยังตัวแปรสภาพแวดล้อมของคุณ (เช่นใน ไฟล์ชุด นอกจากนี้ยังให้แน่ใจว่าคีย์ mnemonic หรือ private ของคุณอยู่ใน env var (เช่น หรือ ). จากนั้นปรับปรุงการกําหนดค่าเครือข่าย ตัวอย่างเช่นเพื่อใช้ Ethereum Sepolia testnet ผ่าน 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 ... }; นั่นคือมัน! การเปลี่ยนแปลงที่สําคัญคือ URL: we used ด้วยของเรา พารามิเตอร์คําถาม ตอนนี้ทุกครั้งที่คุณเรียกใช้ Truffle กับ เครือข่ายจะนําทางผ่าน GetBlock แทน Infura หากคุณต้องการกําหนดค่า Mainnet คุณสามารถเพิ่มส่วนที่คล้ายกันได้: 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 } ตรวจสอบให้แน่ใจว่าแทนที่ด้วยที่ถูกต้อง สําหรับเครือข่ายของคุณ ( Ethereum mainnet คือ 1 Sepolia คือ 11155111 ฯลฯ ) บันทึกการเปลี่ยนแปลงของคุณในไฟล์การกําหนดค่าของคุณ network_id โซ เป็นสิ่งที่ใช้ที่นี่ แต่ GetBlock ยังสนับสนุนการแทรกคีย์ในเส้นทาง (เช่นที่คุณอาจเห็นในตัวอย่างบางอย่าง) ทั้งสองมีสอดคล้องกัน มันเป็นเรื่องธรรมดามากขึ้นในการใช้พารามิเตอร์คําถามและง่ายต่อการจัดการกับเทมเพลต string หมายเหตุ https://eth.getblock.io/<network>/?api_key=.. ขั้นตอนที่ 4: การใช้และทดสอบ web3.js ด้วย GetBlock ก่อนส่งสัญญาของคุณเป็นความคิดที่ดีที่จะตรวจสอบว่าทุกอย่างได้รับการกําหนดค่าอย่างถูกต้อง คุณสามารถทําได้ในหลายวิธี: 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)); อย่าลืมที่จะโหลดตัวแปรสภาพแวดล้อมของคุณ (คุณสามารถเพิ่ม ด้านบนและกําหนด GETBLOCK_API_KEY ใน .env ของคุณ) ดําเนินการสคริปต์นี้ด้วย หากพิมพ์หมายเลขบล็อกคุณจะเชื่อมต่อกับ GetBlock โดยใช้ web3.js require('dotenv').config(); node test-getblock.js การทดสอบข้างต้นใช้การโทรอ่านที่เรียบง่าย ( ). คุณสามารถลองเพิ่มเติมเช่นการเรียกเก็บบล็อกหรือสมดุลบัญชีเพื่อยืนยันเพิ่มเติมว่าสิ่งที่ทํางาน ตัวอย่างเช่น: eth_getBlockNumber const latestBlock = await web3.eth.getBlock('latest'); console.log("Latest block info:", latestBlock); หากสิ่งบางอย่างผิดพลาด (เช่นคุณจับข้อผิดพลาดในการตรวจสอบความถูกต้อง) ตรวจสอบให้แน่ใจว่าคีย์ API ของคุณใน URL ที่ถูกต้องและขีด จํากัด ฟรีของบัญชีของคุณไม่ได้เกิน (ไม่น่าจะเป็นกับคําขอเพียงไม่กี่คํา) หากคุณเคยใช้ผู้ให้บริการ Web3 ของ Alchemy หรือ Infura ในรหัส (เช่น Alchemy เสนอลูกค้า Web3 หรือ SDK ที่มีวิธีการที่กําหนดเอง) การเปลี่ยนไปยัง GetBlock จะหมายความว่าคุณยังคงใช้วิธีการ Web3 ที่พื้นฐาน GetBlock เป็นผู้ให้บริการโซ่ปกติดังนั้น web3.js จะพูดคุยกับมันผ่านการโทร Ethereum JSON-RPC มาตรฐาน สําหรับ Tip ขั้นตอนที่ 5: ดําเนินการย้าย Truffle และทดสอบบน GetBlock และในที่สุดการทดสอบที่แท้จริง - การใช้สัญญาของคุณและโฮสติ้ง DApp ของคุณด้วย GetBlock เป็นผู้ให้บริการด้านหลังของคุณ จัดการสัญญาตามปกติกับ Truffle แต่สั่งให้ใช้ในเครือข่ายที่คุณสร้างสําหรับ GetBlock ตัวอย่างเช่น: การใช้สัญญา truffle migrate --network sepolia Truffle จะรวบรวมสัญญาของคุณ (หากไม่ได้รวบรวมแล้ว) แล้วใช้ HDWalletProvider เพื่อออกอากาศธุรกรรมการใช้งานบน GetBlock RPC คุณควรจะสามารถดูการส่งออกในคอนโซลของธุรกรรมที่ส่ง, การยืนยันที่ได้รับ ฯลฯ กระบวนการนี้เหมือนกับ Infura / Alchemy - ความแตกต่างเพียงอย่างเดียวที่อยู่เบื้องหลังสถานการณ์คือ URL โนด เมื่อใช้ Ethereum mainnet ให้แน่ใจว่าคุณมีจํานวน ETH ที่เหมาะสมในบัญชีผู้ใช้ของคุณและให้ความสนใจกับราคาก๊าซ คําสั่งการย้ายจะเป็น (ทําของคุณ ประสบการณ์ควรจะเหมือนกับของ Infura: GetBlock เพียงแค่ส่งต่อการทําธุรกรรมที่ลงนามของคุณไปยังเครือข่าย Ethereum truffle migrate --network mainnet mainnet หากคุณมีการทดสอบ Truffle หรือสคริปต์ที่อ้างอิงสัญญาของคุณคุณสามารถทดสอบได้บนเครือข่ายที่นําเสนอโดย GetBlock เช่นกัน: การทดสอบการทํางาน truffle test --network sepolia นี้จะเรียกใช้ชุดทดสอบของคุณบนจุดสิ้นสุด GetBlock การทดสอบธุรกรรม (เช่นการเรียกใช้ฟังก์ชั่นสัญญาในสัญญาที่คุณใช้) จะถูกส่งผ่านผ่านท่อ GetBlock อีกครั้งคุณไม่ควรเห็นความแตกต่างใด ๆ ในพฤติกรรม ด้วยกี่ข้อยกเว้นการเปลี่ยนจุดปลายทาง RPC ไม่ควรมีผลต่อพฤติกรรมของ Ethereum หากการย้ายหรือการทดสอบของคุณทํางานได้ดีบน Infura / Alchemy พวกเขาควรทํางานได้ดีบน GetBlock การโทร JSON-RPC แบบเริ่มต้นทั้งหมดได้รับการสนับสนุนสําหรับ GetBlock (เช่นการใช้งานสัญญาการอ่านสถานะการส่งธุรกรรมการสอบถามเหตุการณ์) - มันเป็นบริการโซลูชั่นแบบเต็มรูปแบบ หากการโทร JSON-RPC ได้ถูกลบออกด้วยเหตุผลใด ๆ คู่มือของ GetBlock โดยปกติจะแสดงให้เห็น แต่การโทรง่ายเช่นการใช้งาน ( ), โทรศัพท์ ( ), การรับใบรับรอง ฯลฯ ทั้งหมดสามารถใช้ได้ การพฤติกรรมที่คาดหวัง eth_sendRawTransaction eth_call ขอแสดงความยินดี! ภายหลังของ DApp ของคุณตอนนี้อยู่ใน GetBlock! การย้ายของคุณเสร็จสมบูรณ์ การโทรเว็บ3 ของคุณใช้โครงสร้างพื้นฐานของ GetBlock และสัญญาอัจฉริยะของคุณมีชีวิตอยู่ การจัดการ API Keys, Rate Limits และตรวจสอบบน GetBlock การเปลี่ยนแปลงผู้ให้บริการไม่เพียง แต่เป็นเรื่องของการอัปเดต URL - นอกจากนี้ยังจําเป็นต้องรู้ว่ามีความแตกต่างในการติดตามการใช้งานเช่นเดียวกับการตรวจสอบประสิทธิภาพของ DApp ของคุณบนผู้ให้บริการใหม่ มีบางจุดที่จะจําไว้เมื่อคุณเปลี่ยนจาก Infura / Alchemy ไปยัง GetBlock Infura ใช้ ID โครงการใน URL; Alchemy ใช้คีย์ API มากขึ้นในรูปแบบที่บูรณาการใน URL เช่นกัน (หรือโดเมนที่กําหนดเอง) วิธีการของ GetBlock ยังคล้ายกัน – คุณจะมี token การเข้าถึง (คีย์ API) และคุณเพิ่มนี้ไปยัง URL RPC ในระดับฟังก์ชั่นแอปพลิเคชันของคุณไม่จําเป็นต้องทําให้คีย์ของคุณทําอะไรผิดปกตินอกเหนือจากการรวมอยู่ใน URL Endpoint เช่นเดียวกับเมื่อคุณได้รับการรักษาความปลอดภัย Infura Project ID หรือคีย์ API Alchemy ของคุณให้คีย์ GetBlock (จัดเก็บในตัวแปรสภาพแวดล้อมไม่ใช่รหัสด้านลูกค้า) API Key Setup มีข้อ จํากัด ต่อผู้ให้บริการในระดับฟรี: อัตรา จํากัด และผ่าน 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. อีกประเด็นที่น่าตื่นตาตื่นใจของ GetBlock คือแผงควบคุมที่มีการวิเคราะห์ที่สมบูรณ์ ในหน้าหลักของแผงควบคุมของคุณคุณจะได้รับภาพรวมของแผนปัจจุบันของคุณ CUs ที่เหลือสําหรับวันขอบเขต RPS ของคุณปัจจุบันและคําขอ cumulative ที่ทําใน 24 ชั่วโมงที่ผ่านมา นี้ช่วยให้คุณทราบทันทีว่าคุณถึงขอบเขตประจําวันหรือไม่ นอกจากนี้ในแท็บ "สถิติ" หรือ "Analytics" ของจุดสิ้นสุดของคุณ GetBlock ให้กราฟและการแตกหักของ: การตรวจสอบการใช้งาน จํานวนคําขอตามเวลา สถานะการตอบสนอง (ดังนั้นคุณสามารถดูว่ามีข้อผิดพลาดใด ๆ) Method call distribution (which RPC methods you’re calling the most) การปฏิเสธขีด จํากัด อัตราใด ๆ (หากคุณเข้าถึงขีด จํากัด RPS) การตรวจสอบเมตริกเหล่านี้จะแนะนําอย่างมากโดยเฉพาะอย่างยิ่งเมื่อคุณเปลี่ยนไป ตัวอย่างเช่นถ้าคุณเขียนสคริปต์โดยผิดพลาดซึ่งทําให้เครือข่ายพองด้วยการโทรแผงควบคุมจะแสดงปริมาณการร้องขอเพิ่มขึ้นหรือแม้กระทั่งการตอบสนองที่จํากัดอัตรา 429 นี่คือสถานที่ที่คุณต้องการเพิ่มประสิทธิภาพการโทรด้านหลังของ DApp ของคุณ Infura และ Alchemy ยังมีแผงควบคุม แต่ข้อได้เปรียบของ GetBlock คือคุณสามารถติดตามการใช้งานหลายโซ่ทั้งหมดของคุณจากสถานที่เดียว ในกรณีที่แผนฟรีไม่เพียงพอ (อาจ app ของคุณจะขยาย) GetBlock มีการอัพเกรดง่าย – แผน Starter (~50M CUs / เดือน, ~1.6M / วัน, 25 RPS) และแผน Pro (600M / เดือน, 200 RPS) คุณสามารถอัพเกรดโดยตรงจากตาราง แต่ในระหว่างการพัฒนาคุณอาจไม่จําเป็นต้องใช้สิ่งนี้ โปรดทราบว่า CUs ทุกวันที่ไม่ได้ใช้ในแผนฟรีไม่ถูกนําไปใช้ (พวกเขารีเซ็ตทุกวัน) ดังนั้นจึงไม่คุ้มค่าที่จะบันทึกการโทร – เพียงใช้สิ่งที่คุณต้องการ ขีด จํากัด การกระทํา แผนฟรี GetBlock รวมถึงการสนับสนุนสําหรับ 2 tokens การเข้าถึง (จุดสิ้นสุด) ซึ่งหมายความว่าคุณสามารถสร้างหนึ่งสําหรับ mainnet, หนึ่งสําหรับ testnet นั่นคือ – เก็บโครงการหรือสภาพแวดล้อมของคุณแยกต่างหาก แต่ละจุดสิ้นสุดจะมีคีย์ API และการติดตามการใช้งานของตัวเอง นี่คือการเปรียบเทียบกับวิธีการ "Project ID per project" ของ Infura มันเป็นแนวทางที่ดีที่จะมีจุดสิ้นสุดแยกต่างหากสําหรับนักพัฒนา versus การผลิตเพื่อให้คุณสามารถติดตามการใช้งานได้อย่างอิสระ หลายจุดสิ้นสุด แนวทางปฏิบัติที่ดีที่สุดสําหรับการย้ายที่ราบรื่น นี่คือสิ่งที่ฉันแนะนําให้คุณ: 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. ข้อสรุป โดยการทําตามกวดวิชานี้คุณได้ย้าย backend ของ Ethereum DApp ของคุณจาก Infura / Alchemy ไปยัง GetBlock การกําหนดค่า Truffle ของคุณตอนนี้หมายถึง RPC ของ GetBlock และคุณสามารถใช้สัญญาและทําการโทรผ่าน web3.js ผ่าน GetBlock ในลักษณะเดียวกันที่คุณสามารถทําได้ก่อน การย้ายจะไม่เปลี่ยนฟังก์ชั่นของ DApp ของคุณ แต่ก็ตั้งตําแหน่งให้คุณสามารถเพิ่มบล็อกเชนเพิ่มเติมหรือเพิ่มการใช้ได้โดยไม่ต้องเรียกใช้ nodes ของคุณเอง