Introduction
Gas abstraction, often referred to as gas sponsorship, is a core feature of the TrueChain network. This mechanism allows the transaction's sender (the from address) and the address that actually pays the gas fee to be different. This design enables a seamless experience for new users of DApps and other applications.
They can perform on-chain actions like data recording, registration, or voting without needing to understand complex blockchain account systems or acquire the native cryptocurrency first. Instead, the application provider or a third-party service can cover the transaction costs.
This system requires adjustments to the transaction's structure, signing process, and sending method compared to standard Ethereum transactions. A gas-sponsored transaction typically requires signatures from two accounts, making the process slightly more involved but far more flexible for end-users.
How Gas Sponsorship Works
In a standard blockchain transaction, the account initiating the action also pays the required gas fee. TrueChain’s gas abstraction decouples these two roles.
The first signature comes from the transaction's originator (the from address). This creates a pre-sponsorship transaction. The second signature is provided by the account that will pay the gas fee (a new payment address). This final signature creates a TrueRawTransaction that can be broadcast to the network via an RPC interface.
In most envisioned use cases, the two signatures are completed on different sides of a service. A client-side user generates the pre-sponsorship transaction with their account and sends it to a dedicated sponsorship signing service, which then provides the second signature.
Transaction Structure Differences
Compared to a standard Ethereum transaction, a TrueTransaction on the TrueChain network introduces two new optional fields:
fee-String: An additional fee paid to the miner. In the future, this field will be queryable within smart contracts, allowing high-value STO project contracts to set a minimum user手续费 (handling fee) threshold.payment-32 Bytes: The address of the sponsorship account. If this field is not empty and the signature is valid, the gas fee will be deducted from the sponsor's account balance instead of thefromaccount's balance.
Thepaymentaddress is explicitly declared in the transaction structure for a critical reason. While a node could derive this address from the signature, declaring it prevents a scenario where a sponsor (or a malicious actor) could refuse to sign and instead send the transaction directly to the node. This would result in the unsuspecting initiator (fromaddress) being charged the gas fee, which is not the intended behavior.
The Signing Process
The web3t.eth.accounts object has been extended with updated and new methods to handle this two-step signing process. These methods are also accessible directly on an Account object.
signTransaction
This method is based on web3.js's like-named method but includes new optional parameters in the input object for the TrueChain-specific fields.
Parameters:
The tx object can now include:
fee-String: The additional miner fee, in wei. Defaults to 0.payment-String: The sponsorship account address. Defaults to empty.
Returns:
The object passed to the callback or Promise includes new fields:
trueHash-String: The message hash calculated including the two new transaction parameters.trueRawTransaction-String: The RLP encoded signed transaction, which includes the new parameters. If no sponsorship signature is needed, this can be sent directly usingweb3t.eth.sendSignedTrueTransaction().
The method will also perform a standard Ethereum transaction signature (ignoring the fee and payment parameters) and provide that compatible signed transaction information in the original fields.
signPrePaymentTransaction
As the name implies, this method signs a pre-sponsorship transaction. The output cannot be sent to the network; it is used solely for the next step, where the actual gas-paying account signs it to generate the final TrueRawTransaction.
Parameters:
This method accepts parameters identical to signTransaction:
tx-Object: The extended TrueTx transaction object.privateKey-String: The private key of the transaction initiator (fromaddress).callback-Function: (Optional) Callback function.
Returns:
A Promise that resolves to an object containing:
messageHash-String: The hash of the transaction parameters.r, s, v-String: Components of the ECDSA signature.preSignedRawTx-String: The RLP encoded pre-sponsorship signed transaction, including the transaction data, the first signature, and supplemental info likechainId. This is used as input forsignPaymentTransaction.
signPaymentTransaction
This method performs the second signature on a pre-signed sponsorship transaction, authorizing the specified account to pay the gas fee. Crucially, this method is synchronous—it signs the data contained within the preSignedRawTx and does not need to fetch external data like nonce from a node.
Parameters:
preSignedRawTx-String: The pre-sponsorship transaction string obtained fromsignPrePaymentTransaction.privateKey-String: The private key of the account that will pay the gas fees (paymentaddress).callback-Function: (Optional) Callback function.
Returns:
A Promise that resolves to an object containing:
messageHash-String: The hash of the transaction parameters.r, s, v-String: Components of the ECDSA signature from the sponsor.rawTransaction-String: The final, fully signed RLP encodedTrueRawTransaction, ready to be sent to the network.
Sending the Transaction
sendSignedTrueTransaction
Use this method to send a fully signed TrueTransaction. The calling syntax and returned data format are consistent with web3.js's sendSignedTransaction. The key difference is that sendSignedTransaction can only send standard Ethereum transactions. Any transaction containing a fee or payment field must be sent using sendSignedTrueTransaction to be processed correctly by the TrueChain network.
Ready to implement gas abstraction in your dApp? 👉 Explore advanced transaction methods
Frequently Asked Questions
What is gas abstraction/sponsorship?
Gas abstraction is a blockchain feature that allows a third party to pay the transaction fee on behalf of the user. This means the person initiating a smart contract interaction doesn't need to hold or spend the native cryptocurrency, lowering the barrier to entry for new users.
Why would a project use gas sponsorship?
Projects use sponsorship to improve user experience. It eliminates the need for users to acquire crypto before their first interaction, which can be a significant hurdle. This is ideal for onboarding non-crypto-native users, running promotional campaigns, or handling bulk operations like airdrops where the company covers the costs.
What are the security implications for the sponsor?
The sponsor only signs to pay for gas, not to approve the transaction's actions. The sponsor cannot change the destination, value, or data of the transaction initiated by the user. Their signature solely authorizes the payment of the network fee for that specific, user-signed transaction.
Can any transaction be sponsored?
Technically, yes, as the sponsorship mechanism operates at the network level. However, the sponsor (whether a dApp or a service) will likely implement policies. They may only sponsor certain types of transactions (e.g., user registrations) or set limits on gas prices to control costs and prevent abuse.
What happens if the sponsor's account has insufficient balance?
The transaction will fail, just like any other transaction that cannot cover its gas costs. The network node will validate that the payment address has enough balance to pay the estimated gas * gasPrice before including the transaction in a block. If it doesn't, the transaction will be rejected.
How does this differ from meta-transactions or ERC-2771?
The core concept is similar: separating fee payment from transaction initiation. However, gas abstraction on TrueChain is implemented as a native protocol feature rather than through a system of smart contracts and relayers. This can potentially offer greater efficiency, reduced gas costs overall, and simpler integration for developers.