通常、Ethereumの開発者は、Ethereumノードへの容易なアクセスを Infura または Alchemy に依存します。 GetBlock は、複数のチェーンサポート、寛大な無料レベル、優れた安定性を提供する魅力的な代替です。このチュートリアルでは、Infura/Alchemy から GetBlock に Truffle + web3.js バックエンドを移行する方法を発見します。 GetBlockにサインアップし、 RPCエンドポイントを取得するには、 トリプルを再構成し、 Web3のコネクティビティテスト 展開を進め、そして 利率を比較し、差異を監視する。 You need an existing Ethereum DApp project with Truffle, and Node.js installed. I assume you have been using Infura or Alchemy (with a project ID or API key) and have a mnemonic or private key available for deployment. さあ、始めよう! 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. 最後に、GetBlockのダッシュボードにはいくつかの素晴らしいモニタリングと分析機能があり、私たちはすぐにそれにアクセスします。 Step 1: Register for a GetBlock Account 最初のステップは、無料の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アカウントは1〜2分で入手できます。 注: GetBlock ダッシュボードは、API エンドポイントを管理し、使用状況を監視し、設定を調整する場所です。サインインした後、前に進み、ご覧ください。アカウント設定でユーザー ID が表示されます(サポートが必要な場合は有用ですが)、さらに重要なことは、次にプロジェクトエンドポイントを設定します。 Step 2: Get Your GetBlock RPC Endpoint (API キーと URL) アカウントを作成すると、Ethereumネットワーク(またはあなたが必要とするネットワーク)のためのRPCエンドポイントを作成する必要があります。これにより、Infura/Alchemyの代わりに使用するHTTP URL(および必要に応じたWebSocket URL)が提供されます。 新しいエンドポイントを作成する: In the GetBlock Dashboard, find the "Create Endpoint" or "Add New Endpoint" button. Click on it to start creating a new connection. 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」)の名前/ラベルを提供して、1 つ以上のエンドポイントを設定する場合に追跡を容易にする。 作成または確認をクリックします. ダッシュボードは、エンドポイントの詳細を生成します。 作成後、あなたはあなたのエンドポイントのためのRPC URLを見るべきです。 GetBlock は、同じエンドポイントの WebSocket URL (wss:// から始まる) を表示し、アプリケーションが WebSockets (サブスクリプションやライブイベント) を必要とする場合、それを利用できます。 GetBlock API キーを安全に保存してください. 公開レポまたはクライアント側のコードにコミットしないでください. 最良の実践は、環境変数として保存したり、ソースコントロール外でファイルを構成したりすることです. I will demonstrate with environment variables in the next step. 大事な You now have a GetBlock endpoint URL and API key, ready to use. Now, let's insert that into Truffle. Step 3: Truffle Configuration を変更して 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 ... }; 私たちの目標は、Infura URL を GetBlock URL に置き換えることです(および Alchemy URL の場合も同様です)。良いニュースは GetBlock の RPC が同じように機能していることです - あなたはエンドポイント URL と財布プロバイダーを提供します。 Truffle プロジェクトが既に使用されていない場合 (Infura/Alchemyを介して展開した場合、インストールする可能性があります。 このライブラリでは、Truffle があなたのキーでトランザクションを署名し、リモートノードを通じて送信することができます。 Install HDWalletProvider. @truffle/hdwallet-provider npm install @truffle/hdwallet-provider 修正 GetBlock API キーを環境変数に追加します(例えば、 ファイルセット ) また、あなたのメモニックまたはプライベートキーが 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 わたしたちと クエリパラメータ. Now, whenever you run Truffle with the ネットワークでは、Infura ではなく GetBlock を経由してルーティングします。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 THE これはここで使用するものですが、GetBlockはパスにキーを埋め込むこともサポートします(いくつかの例で見ることができます)。 メモ。 https://eth.getblock.io/<network>/?api_key=.. ステップ 4: GetBlock で web3.js をデプロイしてテストする 契約を送信する前に、すべてが正しく設定されていることを確認するのが良いアイデアです。 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 で定義します。 ブロック番号を印刷する場合、Web3.js 経由で GetBlock に成功して接続しました。 require('dotenv').config(); node test-getblock.js 上記のテストは、単純な読書呼び出しを使用します( ) ブロックまたはアカウントのバランスを取得するなど、より多くの方法を試してみて、事態が機能していることをさらに確認できます。 eth_getBlockNumber const latestBlock = await web3.eth.getBlock('latest'); console.log("Latest block info:", latestBlock); これらのリクエストはすべてGetBlockのノードを通過します。何かが間違っている場合(たとえば、認証エラーが発生します)、URLのAPIキーが正しく、アカウントの無料制限が超えられていないことを確認してください(わずか数件のリクエストでは非常に不可能です)。 以前 Alchemy や Infura の web3 プロバイダーをコードで使用したことがある場合(すなわち、Alchemy はカスタムメソッドを持つ Web3 クライアントまたは SDK を提供しています)、GetBlock に切り替えることは、まだ基本的な Web3 メソッドを使用していることを意味します GetBlock は通常のノードプロバイダーなので、web3.js は標準的な Ethereum JSON-RPC 通話を通じてそれに話します。 ティップについて Step 5: Run Truffle Migrations and Tests on GetBlock そして最後に、実際のテスト - あなたの契約を展開し、あなたのバックエンドプロバイダーとしてGetBlockとあなたのDAppをホスティングします。 通常、Truffle で契約を展開しますが、GetBlock で作成したネットワークに展開するように指示します。 契約の展開 truffle migrate --network sepolia Truffle はあなたの契約をコンパイルします (すでにコンパイルされていない場合) 次に HDWalletProvider を使用して、GetBlock RPC で展開トランザクションを放送します. You should be able to view output in the console of transactions sent, confirmations received, etc. The process is the same as it was with Infura/Alchemy - the only difference behind the scenes is the node URL. Ethereum mainnet にデプロイする際には、デプロイアウトアカウントに合理的な金額の ETH を持っていることを確認し、ガス価格に注意してください。 (Make Your 体験は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 にあります! あなたの移行は完了しました。 あなたの web3 通話は GetBlock のインフラストラクチャを利用しており、あなたのスマート コントラクトはライブです。 API キー、料金制限、および GetBlock の監視の処理 プロバイダーを変更することは、URLを更新するだけでなく、使用がどのように追跡されているか、そして新しいプロバイダーでのDAppのパフォーマンスを監視する場合の違いを知ることも必要です。 Infura は URL にプロジェクト ID を使用しました; Alchemy は URL に埋め込まれたフォーム (またはカスタムドメイン) で API キーをより頻繁に使用しました。 GetBlock のアプローチは同じです - あなたはアクセス トークン (API キー) を持っており、これを RPC URL に追加します。 API キーの設定 フリーレイヤーには、プロバイダーごとに制限があります: 制限値と経過値 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のもう一つの素晴らしい側面は、完全な分析を備えたダッシュボードです。あなたのダッシュボードのメインページでは、現在のプラン、残りの1日のCU、現在のRPS値、そして過去24時間の累積的なリクエストの概要が表示されます。これにより、あなたが日々の限界に達しているかどうかをすぐに知ることができます。さらに、あなたのエンドポイントの「統計」または「アナリティクス」タブで、GetBlockは以下のグラフとブロックを提供します: 使用の監視 期間中の申請件数 応答状態(エラーがあったかどうかを確認するため) メソッド呼び出し配布(あなたが最も呼び出しているRPCメソッド) 料金制限の拒否(RPS制限に当たった場合) たとえば、ネットワークを呼び出しに浸透させるスクリプトを誤って書いた場合、ダッシュボードはリクエストボリュームの増加または約429レート制限応答を示します。これがあなたのDAppのバックエンド呼び出しを最適化したい場所です。InfuraとAlchemyはダッシュボードも提供しますが、GetBlockの利点は、1つの場所からすべてのマルチチェーン使用を追跡することができます。 無料プランが十分でない場合(おそらくあなたのアプリが拡大している場合)、GetBlockには簡単なアップグレードがあります - スタートプラン(~50M CUs / month, ~1.6M / day, 25 RPS)とプロプラン(600M / month, 200 RPS)です。あなたはデスクトップから直接アップグレードすることができます。しかし、開発中に、あなたはそれを必要としません。また、無料プランの未使用の毎日のCUは運ばれていないことに留意してください(彼らは毎日のリセット)ので、電話を節約する価値はありません - 必要なものを使用するだけです。 行動制限 GetBlock フリープランには最大 2 つのアクセス トークン (エンドポイント) のサポートが含まれています。これは、メインネット、テストネットの 1 つを作成することを意味します. つまり、プロジェクトや環境を孤立させます. 各エンドポイントには独自の API キーと使用追跡があります. これは Infura の「プロジェクト ID per プロジェクト」アプローチに匹敵します. 独立して使用を追跡できるように、開発者と生産のための別々のエンドポイントを持つことは良い実践です。 複数のエンドポイント シームレスな移住のためのベストプラクティス 以下、私がお勧めするもの: 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. 結論 このチュートリアルに従って、あなたは今、Infura/AlchemyからGetBlockにEthereum DAppバックエンドを移行しました。あなたのTruffle構成は今、GetBlockのRPCを指し、あなたは契約を展開し、GetBlockを通じてWeb3.jsの呼び出しを行うことができます以前と同じように。移行はあなたのDAppの機能を変えることはありませんが、それは簡単に追加のブロックチェーンを追加したり、独自のノードを実行することなく使用を増やすことができます。