Skip to main content
EVM

Learn how Hana Wallet injects an Ethereum provider for EVM-compatible dApps, making integration straightforward for developers.

David avatar
Written by David
Updated over a week ago

Introduction to Hana's Ethereum Provider

Hana Wallet simplifies the integration of EVM-compatible dApps by injecting an Ethereum provider into the webpage whenever an EVM chain is enabled. This functionality mirrors the behavior of MetaMask, following the EIP-1193 standard, making it easy for developers to adapt their dApps for Hana.

How Hana’s Ethereum Provider Works

  • Automatic Injection: When an EVM chain is enabled, Hana injects its Ethereum provider directly into the webpage. This allows dApps that are compatible with MetaMask, such as Uniswap and OpenSea, to work out of the box with Hana.

  • Compatibility with MetaMask: If a user has MetaMask installed, Hana will not inject its provider, ensuring that existing MetaMask applications function without interference. However, dApp developers can offer users the option to override the MetaMask provider with Hana’s Ethereum provider.

Example Code to Detect and Use Hana’s Ethereum Provider

Here’s how you can detect if Hana Wallet is available and how to utilize its Ethereum provider:

if (window.hanaWallet?.available) { 
// Hana is available

console.log(window.hanaWallet.version);
// Example output: 2.2.1

// Hana's Ethereum provider will be available as window.hanaWallet.ethereum after it is initialized

// You might need to delay this check if your script is running before Hana's provider has initialized
if (window.hanaWallet.ethereum) {
// window.ethereum could be provided by Hana or other EVM wallets (e.g., MetaMask)
// Hana won't replace window.ethereum if another wallet has already set it
if (window.ethereum?.isHanaWallet) {
// Hana's Ethereum provider includes a non-standard isHanaWallet: true property
// Hana (and many EVM wallets) also sets the isMetaMask: true property
}

// If you want to prefer Hana's Ethereum provider, or give the user a choice
// You can store the provider that you want to use in local state
let ethereumProvider = window.ethereum;
// ethereumProvider could now be Hana, MetaMask, or another EVM wallet

ethereumProvider = window.hanaWallet.ethereum;
// ethereumProvider is now definitely Hana's Ethereum provider
}
}

Why Use Hana for Your EVM dApp?

  • Easy Integration: Hana Wallet’s Ethereum provider is designed to work seamlessly with existing EVM dApps, making it easy for developers to integrate without significant changes to their code.

  • MetaMask Compatibility: Hana is fully compatible with MetaMask, ensuring that users with MetaMask installed can continue using it without issues. Developers can also offer users the option to switch to Hana’s provider if desired.

  • Flexibility and Control: Developers can detect Hana’s provider and decide whether to use it over other providers, offering flexibility in how the dApp interacts with different wallets.

Additional Resources

For more detailed information on how to work with Ethereum providers like the one Hana injects, you can refer to the official MetaMask documentation here: MetaMask Ethereum Provider Guide.

Integrating your EVM-compatible dApp with Hana Wallet is straightforward, thanks to its automatic Ethereum provider injection and compatibility with MetaMask. Whether you want to give users the choice of wallet provider or simply ensure that your dApp works across multiple platforms, Hana Wallet makes it easy.

Need Help?

If you have any questions or need further assistance, visit our Support Center for more articles and resources, or contact our support team.

Did this answer your question?