A blockchain developer building a decentralized application faces a fundamental decision: how to let users transact without requiring them to paste private keys into a webpage or move assets to a centralized custodian. The answer lies in wallet provider injection and signed transaction authorization. Instead of hosting user funds or keys, a dApp can ask the user’s installed wallet to sign transactions on their behalf, keeping private keys stored locally on the user’s device. Bitget Wallet’s SDK and provider injection model enables this workflow across 90+ blockchains, letting developers integrate asset management, token swaps, and DeFi interactions without building their own key-management infrastructure.
The technical question is not whether such integration is possible—it is how to implement it correctly, handle multiple chains, manage transaction state during long operations, and ensure that users understand what they are signing before confirmation. A misconfigured integration can expose users to signing unintended transactions, drain assets to wrong addresses, or fail silently during critical steps. This guide explores the architectural decisions, code patterns, and security practices that separate a production-ready dApp integration from a prototype that appears functional but fails under real load or adversarial conditions.
The wallet provider injection pattern and its security model
When a user installs the Bitget Wallet app, the browser extension (or mobile WebView) injects a global object into the webpage’s JavaScript context. This injected object is not the wallet itself; it is a proxy interface that allows the dApp to request operations such as reading the connected account, fetching the current network, or asking the user to sign a transaction. The actual private key never leaves the wallet application. The dApp receives signed transaction data and can broadcast it to the blockchain.
This architecture moves trust responsibility. The dApp no longer holds keys, reducing the impact of a dApp server compromise. However, the dApp still controls what the user is asked to sign. A malicious or careless dApp can construct transactions that drain wallets, swap tokens at predatory rates, approve infinite token allowances, or send funds to attacker-controlled addresses. The wallet displays confirmation dialogs showing the transaction details, but the user’s understanding of those details depends on transparency and accurate rendering. A complex transaction or deliberately confusing interface can defeat the protection.
The Web3 gateway model treats the wallet as a secure intermediary rather than a passive signer. Because the wallet maintains the connection to the user’s account and holds the device’s biometric or PIN protection, it can enforce rate limits on approvals, warn users when transaction patterns look unusual, or block known malicious dApps if the wallet maintainer publishes a list. Bitget Wallet’s non-custodial architecture means the wallet provider cannot unilaterally freeze funds, but it can interrupt the signing flow if conditions look unsafe.
From a developer perspective, this means assuming the wallet will refuse to sign some requests. A dApp must handle the case where a transaction is initiated but the user cancels or the wallet rejects it. Timeouts, network latency, and user abandonment are also normal failure modes. A production integration cannot rely on synchronous assumptions or retry logic that bombards the user with repeated signing requests.
Provider detection and network handling across 90+ blockchains
The first step in any dApp integration is detecting whether Bitget Wallet (or another compatible provider) is available. The detection pattern is straightforward: check the injected object, attempt to read the account, and handle the case where the wallet is not installed. Detection should not block page load or force the user to install the wallet before exploring the dApp. A user may decide to use a different wallet, and the dApp should accommodate that choice or clearly indicate its requirements.
Once the wallet is detected, the dApp must determine which blockchain network the wallet is currently connected to. Bitget Wallet supports Ethereum, Binance Smart Chain, Polygon, Solana, Aptos, Arbitrum, Optimism, Base, and dozens of other networks. A dApp cannot assume a particular network. It must either request that the user switch to the required network or operate across multiple networks simultaneously. Requesting a network switch is straightforward when the wallet supports it, but the request can fail if the network is not added to the wallet’s configuration. Fallback logic—such as displaying instructions for manual network addition—prevents the dApp from appearing broken.
For dApps serving multiple chains, the architectural choice is between handling all chains in a single transaction flow or creating separate flows per network. A decentralized exchange built on Bitget Wallet might support swaps on Ethereum and Polygon independently, with separate liquidity pools and fee structures. Switching between them seamlessly requires that the dApp understand each network’s token contracts, gas models, and confirmation times. A shortcut approach—using a bridge or wrapped token—simplifies the interface but adds counterparty risk and slippage.
The most robust pattern is to let the user select a target network explicitly before constructing a transaction. The dApp’s state should track the selected network, validate that all addresses and tokens belong to that network, and refuse to proceed if there is ambiguity. This is especially important for tokens that exist on multiple chains with the same or similar names; a user approving a swap without understanding that they are using a low-liquidity wrapped version instead of the mainnet token has suffered a preventable loss.
Constructing and signing transactions through the provider interface
A dApp constructs a transaction object specifying the target address, amount (or function call), gas parameters, and nonce. The wallet’s provider accepts this object and returns a promise. When the promise resolves, the transaction has been signed. When it rejects, the user cancelled or the wallet refused. This asynchronous model is essential because the wallet may show a confirmation dialog that the user leaves open for hours.
One critical detail: the dApp should not assume that transaction parameters such as nonce, gas price, or network state remain constant between the moment the dApp prepares the transaction and the moment the wallet signs it. A user might open the signing dialog, check the transaction, step away for several minutes, return, and then approve. In the interim, the gas price may have changed, other transactions may have consumed nonces, or the dApp’s state may have updated. Best practice is to refetch critical parameters from the DeFi wallet provider immediately before signing, or to accept that the transaction may be rejected by the blockchain if conditions have changed materially.
For complex operations—such as a multi-step DeFi interaction involving token approval followed by a swap—developers often build a transaction queue. The dApp constructs multiple transactions, presents them to the user for sequential signing, and broadcasts each one only after the previous one is confirmed. This prevents the situation where a swap is signed but the approval failed, causing the swap to revert. However, sequential signing also creates latency, and a user might cancel midway through. The dApp must offer a clear way to undo partial transactions or resume an interrupted flow.
Gas estimation deserves its own careful attention. The dApp calls a blockchain RPC method to estimate gas for a proposed transaction, then adds a safety buffer. If the buffer is too small, the transaction fails due to insufficient gas. If it is too large, the user overpays unnecessarily. The right buffer depends on the transaction type, current network congestion, and the wallet’s risk tolerance. Bitget Wallet can apply its own gas overrides, so the dApp should not assume its estimate is final.
Handling transaction state, confirmations, and failures
After the wallet signs and returns a transaction hash, the dApp’s responsibility is far from complete. The transaction is now pending on the blockchain. It may be included in the next block, in blocks several minutes from now, or never if the gas price is too low or a replacement transaction displaced it. The dApp must track this state, allow the user to monitor confirmation status, and provide options for acceleration or cancellation.
A robust integration stores the transaction hash, target address, and expected outcome in the dApp’s client-side state or in a backend database. It then polls the blockchain via an RPC provider to check confirmation status. When a block is included, the dApp should verify that the transaction succeeded (no revert), had the expected effect, and updated the user’s balance accordingly. If the transaction fails, the dApp should display the revert reason if available, or at minimum indicate that the transaction failed and allow the user to retry.
The confirmation polling pattern requires careful timing. Polling too frequently wastes RPC quota and battery on mobile devices. Polling too infrequently means the user waits a long time to see confirmation. A typical pattern is to poll every 2–5 seconds for the first 30 seconds, then back off to 10–30 second intervals. When confirmation is detected, polling stops. The dApp should also allow the user to manually refresh or abandon a transaction if they do not want to wait.
For networks with variable confirmation times—such as Solana, where finality can be immediate or delayed—the dApp should understand the network’s actual confirmation model rather than applying Ethereum assumptions. Solana does not use gas; it uses a fixed transaction fee and a state-based execution model. Polygon has faster block times than Ethereum. Aptos uses a different transaction structure entirely. A dApp that hardcodes confirmation logic for one network will malfunction on others. Bitget Wallet’s support for 90+ blockchains means the dApp code must be equally flexible.
Building with hardware wallet compatibility and biometric security
Bitget Wallet integrates with hardware wallets such as Ledger and Trezor, allowing users to keep their private keys on a physical device while using the wallet as a signer interface. From the dApp’s perspective, this integration is transparent: the signing flow is identical whether the wallet is using a local key or delegating to a hardware device. However, hardware wallet signing introduces latency and may timeout if the user does not respond promptly on the device.
A dApp should not assume that signing is instantaneous. If the user is using a hardware wallet and must physically confirm each transaction on the device, the signing operation may take 30 seconds or longer. The dApp’s UI should reflect this, displaying a message such as “Awaiting signature confirmation on your hardware wallet” rather than a generic “Processing…” that suggests a connection problem. Timeouts should be generous—at least 2–3 minutes—before concluding that the operation has failed.
Bitget Wallet’s biometric authentication (Face ID on iOS, fingerprint on Android) provides a layer between the dApp and the signing operation. When a user approves a transaction in the wallet, they may be prompted to authenticate before the wallet releases the signature. This is a security feature that prevents someone with temporary access to an unlocked device from draining the wallet. The dApp cannot control or bypass this authentication, and should not attempt to.
For dApps handling high-value transactions or sensitive operations (such as NFT transfers or high-slippage swaps), developers sometimes implement their own confirmation step. This could involve asking the user to re-enter a PIN, solve a CAPTCHA, or confirm the transaction details in a second dialog. While such measures can prevent accidental approvals, they also increase friction and may encourage users to approve transactions without reading them carefully. The security trade-off should be weighed against usability.
Handling token approvals and built-in DEX integration
Many DeFi protocols require a two-step transaction pattern: first, the user approves the protocol to spend up to a certain amount of a token. Second, the protocol transfers that token from the user’s account. Bitget Wallet’s built-in support for token swaps and yield farming means users expect to encounter approval flows regularly. A dApp must construct approval transactions correctly and handle edge cases such as approving zero before increasing the allowance, or revoking approval when no longer needed.
The standard ERC-20 approval function takes two parameters: the spender address (the contract to be allowed to spend the token) and the allowance amount. A dApp has three common patterns. It can request an infinite allowance, saving the user from re-approving on future transactions but exposing the token to risk if the spending contract is compromised. It can request the minimum necessary allowance for the current transaction, maximizing security but requiring a new approval each time. Or it can request a reasonable allowance (such as multiple times the transaction amount), balancing risk and convenience.
A dApp should display the approval step clearly to the user. Many users do not understand that approving a token allowance is a transaction separate from the actual swap or transfer, and they may be confused if asked to approve multiple times. A clear message such as “First, you will approve the swap contract to spend your token. Then, you will execute the swap” sets expectations. If a user cancels the approval step, the dApp should allow them to try again without losing progress on the rest of the flow.
Bitget Wallet’s built-in DEX integration lets users swap tokens without leaving the wallet. A dApp that offers its own swap functionality is competing with this feature. A better approach is to integrate the wallet’s DEX as an option or fallback. If the dApp’s DEX fails or offers poor rates, the user can still complete a swap through the wallet’s integrated tools. This improves the user experience and reduces the dApp’s operational burden.
Cross-platform considerations and user experience patterns
Bitget Wallet is available as a Chrome extension, iOS app, Android app, Windows desktop app, and Mac app. A dApp accessed through different platforms will interact with different wallet implementations, and the developer experience varies. The Chrome extension is the most straightforward: the injection pattern works as described, and provider methods are consistently available. Mobile WebViews (used by iOS and Android wallets when users access a dApp through the wallet’s in-app browser) behave similarly but may have slight performance differences. Desktop applications using WalletConnect or similar protocols introduce additional latency and may timeout differently.
The best practice for cross-platform dApps is to test thoroughly on each platform before launch, not just in the development environment. A dApp that works perfectly in Chrome on desktop might have connection issues in the iOS wallet’s WebView due to different security policies or sandboxing. Mobile users expect faster interactions and tighter timeouts, so a dApp built for desktop may feel sluggish on mobile. Separate logic paths for mobile and desktop, with appropriate timeouts and UI adjustments, often prove necessary.
User experience patterns should prioritize clarity over minimalism. A user who does not understand what they are about to sign is a user who has become a liability. Display the token symbol and amount before asking for approval. Show the destination address prominently. Indicate the estimated gas cost and any slippage or other risks. If the transaction is time-sensitive (such as a DEX swap with a deadline), communicate the urgency without creating panic.
For repeated actions—such as a yield farming dApp where users interact with the same smart contract daily—the dApp can cache allowances and reduce approval requests. However, it must refresh the cached allowance periodically and handle the case where a user revokes approval through a separate interface. Defensive coding assumes that allowances are constantly subject to change.
SDK patterns, error handling, and production deployment
Bitget Wallet provides an SDK or provider interface for JavaScript environments. The SDK documentation specifies the available methods, return types, and error cases. A production dApp should handle all documented error conditions and many undocumented ones. Common errors include network unreachability (the user lost internet), wallet locked (the user closed or reinstalled the wallet), insufficient balance (the user cannot afford the gas), and invalid parameters (the dApp constructed a malformed transaction).
Each error requires different user-facing messaging. If the network is unreachable, the user should be told to check their connection. If the wallet is locked, they should be prompted to unlock it or reinstall it. If the balance is insufficient, they should be shown the shortfall and offered options to reduce the transaction size or cancel. Generic error messages like “Transaction failed” leave users confused and are often a sign of insufficient testing.
Deployment to production should include monitoring and alerting. The dApp should log failed transactions, rejected approvals, and timeout events to a backend service. These logs help identify patterns: if 80% of transactions are timing out, the gas estimation logic may be broken. If all approvals are being rejected, the contract address may be incorrect. A dApp blindly launched without observability often accumulates user complaints before the developers realize there is a systemic problem.
Version management is also critical. If Bitget Wallet publishes a new provider API or the underlying blockchain networks change their RPC methods, the dApp must be updated. Maintaining backward compatibility where possible and testing against multiple wallet versions ensures the dApp remains functional as the ecosystem evolves. A dApp that worked perfectly against Bitget Wallet 1.0 may silently break in production when the user’s wallet auto-updates to version 2.0 if the dApp code was not tested against the new version.
Security practices and avoiding common pitfalls
The most dangerous pitfall is over-trusting the wallet to validate transactions. A dApp might assume that if the wallet signed a transaction, it must be correct. In reality, the wallet only verifies that the transaction is well-formed and that the user confirmed it. It does not verify that the transaction achieves the dApp’s intended outcome. A dApp could accidentally construct a swap that sends tokens to the wrong address, and the wallet will happily sign it if the parameters are valid.
Defensive transaction validation means the dApp should construct transactions, validate them locally before sending to the wallet, simulate them through a blockchain RPC method if available, and verify the result after confirmation. For high-value transactions, a manual code review of the transaction construction logic is also worthwhile. Complex DeFi interactions involving multiple contracts and tokens are particularly prone to errors.
Another critical practice is securing any backend infrastructure that the dApp uses. If a dApp stores user addresses, transaction history, or other metadata in a backend database, that database becomes a target for theft or manipulation. Using HTTPS, rate limiting, input validation, and access controls is the minimum baseline. A compromised backend could inject malicious transactions or steal metadata about user behavior.
The dApp should also avoid common attack vectors such as storing sensitive data in local storage, making assumptions about transaction ordering, or trusting user-supplied input without validation. If the dApp accepts a token contract address from a user, it should fetch the token metadata from a trusted source and display it prominently before the user approves a transaction. A user might paste what they believe is a token address without realizing it is a malicious contract designed to steal approval transactions.
Frequently asked questions
Does Bitget Wallet host my private keys when I use a dApp integrated with its provider?
No. Bitget Wallet is non-custodial, meaning private keys are stored locally on your device and never transmitted to Bitget’s servers. When a dApp requests a transaction signature, the wallet signs it locally and returns only the signed transaction data to the dApp. The dApp cannot access the private key.
What should I do if a dApp asks me to sign a transaction but the details do not match what I intended?
Reject the transaction immediately by canceling the confirmation in your wallet. Do not approve transactions if you do not understand them or if the details look wrong. If you rejected by mistake, the dApp should allow you to initiate a new transaction. Never re-enter your recovery phrase or share it with anyone, regardless of what a dApp claims to need.
Can I use the same dApp across Ethereum, Polygon, and Solana without creating separate accounts?
Yes. Bitget Wallet supports 90+ blockchains, and your wallet account can hold assets on all of them simultaneously. When you connect to a dApp, you can usually switch between networks within the wallet settings. However, the dApp must also support the networks you want to use. Not all dApps are deployed on all blockchains, so verify that your target network is available before attempting to interact.
