Infura Integrates with Polygon to Advance Web 3.0
Infura Transactions (ITX) have come to Polygon! Leveraging the Polygon network to support ITX provides applications with a seamless scaling experience. Specifically, ITX allows end users to send transactions without necessarily holding Ether (ETH). ITX ensures that your transactions are safely submitted and not dropped, while abstracting away the complexities with gas management for developers. This results in more transaction safety for infrastructure development and better user flow with less micromanagement.
Infura serves as the backbone for much of Ethereum’s blockchain development, supporting major DeFi outfits like Uniswap and MakerDAO, the world’s most popular decentralized wallet MetaMask, as well as NFT projects including Sorare and Async Art. Some 350,000 developers are using Infura to build applications for Web 3.0.
ITX is automatically enabled for your projects. You can choose to disable it in your Project Settings.
There are three high-level steps you need to take when integrating ITX in your project:
- On-chain deposit. You generate a private key and deposit some ETH with Infura’s on-chain deposit contract. This action credits your ITX gas tank with the corresponding amount of ETH (after 10 block confirmations). You will use your private key any time you authorize spending from your ITX gas tank.
- Send a relay request. You send a transaction relay request to your usual Infura endpoint using the ‘relay_sendTransaction’ RPC call. ITX will first check if you have sufficient balance, then lock a portion of your funds and relay the transaction on your behalf to the Ethereum network.
- Transaction mined. In an effort to minimize confirmation time and gas paid, ITX will gradually increase the amount of gas you put in and republish the transaction according to a preset schedule. When the transaction does go through, your final transaction fee will be your network fee + ITX fee. You can check your wallet’s new balance of Ethereum tokens by using the ‘relay_getBalance’ RPC call.
Specifically, how do we navigate these three steps? Follow the instructions here:
- Set up the ITX provider. All ITX-specific JSON-RPC methods can be accessed via the ‘ethers.js’ built-in ‘InfuraProvider' class, using your dedicated Infura URL.
- Create a signer account. You will use the private key for authenticating your ITX transaction requests, and its corresponding public address for identifying your ITX gas tank for your Polygon decentralised applications (DApps).
- Check balance. Your signing account needs to have gas tank balance registered with ITX. You can do this by calling the ‘relay_getBalance’ method.
- Make a deposit. And finally, we get to the good part: making a deposit into the ITX gas tank. Note that the contract you’re depositing to (itx.eth) is the same address across all Ethereum networks, and your deposit will be registered after 10 block confirmations.
- Send a Relay Request. The format of an ITX request is as follows:
A slight note on what’s happening under the hood, ITX generates a unique transaction hash for every relay request made by a smart contract. This consists of the ‘keccak256’ hash of the address, the bytes in the data field, a uint value of gas and the chain id. The relay transaction hash is then signed by using the standard Ethereum message signing process.
You only need to pass in the ‘relayTransactionHash’ into the ‘signRequest’ function.
- Example. The code below sends a transaction that calls the ‘echo’ method in a sample contract that is already deployed. ‘relay_sendTransaction’ requires two parameters:
- The relay request object (under const tx = {...} )
- Your signature
Note: The Ethereum transaction hash is changed every time the fee is bumped according to the schedule and the previous hash is no longer reliable for tracking its status. Because the ITX is completely responsible for sending and broadcasting your transaction, you get back a ‘relayTransactionHash’ instead of an Ethereum transaction hash.
- Check your transaction status. There’s a new RPC call ‘relay_getTransactionStatus’ that returns the list of Ethereum Transaction hashes which have been broadcast for the supplied relay ‘TransactionHash’. You can then check client-side whether any of the transaction hashes were mined.
And that’s it! You’ve successfully sent a relay request via the ITX service. From there you can use optimistic rollups, ZK rollups and everything in between. We can’t wait to see how you use the ITX for seamless UX in your Polygon PoS builds!
Keep up with the latest news on Polygon Developers twitter channel, take a deep dive into the available resources or say hi on Discord. Then go build something!
Be a part of our social ecosystem!
Website | Twitter | Ecosystem Twitter| Developer Twitter | Enterprise Twitter | Studios Twitter | Telegram | Reddit | Discord| Instagram | Facebook | LinkedIn