Develop EVM based dApps


Example dApp

Integrate Ethereum dApps with XDEFI


XDEFI injects window.xfi.ethereum as an EIP-1193 compatible provider;

As a dApp developer, you can check if window.xfi && window.xfi.ethereum is defined.

If it is, XDEFI is injected.

You can use it with regular ethereum libraries such as web3 or ethersjs.

Using web3.js

// In Node.js use: const Web3 = require('web3');

let web3 = window.xfi && window.xfi.ethereum && new Web3(window.xfi.ethereum);
if(!web3) {
// XDEFI is not injected

Using ethers.js

const provider = window.xfi && window.xfi.ethereum && new ethers.providers.Web3Provider(window.xfi.ethereum)
if(!provider) {
// XDEFI is not injected


If Pretend to be MetaMask option is enabled in the dApps Settings Providers page, this would make XDEFI overrides window.ethereum and pretend to be MetaMask by having window.ethereum.isMetaMask and window.ethereum._metamask set to true

Using web3.js

// In Node.js use: const Web3 = require('web3');

let web3 = new Web3(window.ethereum);

Using ethers.js

const provider = new ethers.providers.Web3Provider(window.ethereum)

Using onboard.js

Follow the getting started tutorial: https://docs.blocknative.com/onboard

And add the entry of xdefi to the wallets option.

  walletName: "xdefi"

Example of integration with onboard.js: https://github.com/blocknative/react-demo/blob/master/src/services.js#L71 ( live demo https://reactdemo.blocknative.com/ )

Last updated

XDEFI Technologies 2024