Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.16 KB

USAGE.md

File metadata and controls

56 lines (38 loc) · 1.16 KB

Using the library

1. Run

npm i @trustwallet/web3-provider-core

2. Install your desired chain

Let's use for example, ethereum

npm i @trustwallet/web3-provider-ethereum

3. Example usage

import { Web3Provider } from '@trustwallet/web3-provider-core';
import { EthereumProvider } from '@trustwallet/web3-provider-ethereum';

const ethereum = new EthereumProvider();

new Web3Provider({
  strategy: AdapterStrategy.PROMISES,
  handler: (params: IHandlerParams) => {},
}).registerProvider(ethereum);

// Register the ethereum provider
window.ethereum = ethereum;

dApps that use EIP-1193 will be able to connect to your wallet now.


Find more about the chains

  • Cosmos Docs
  • Solana - Wallet Standard fully compatible Docs
  • Ethereum EIP-1193 Docs

Using the callback Adapter

const provider = new Web3Provider({
  strategy: AdapterStrategy.CALLBACK,
}).registerProvider(ethereum);

const handler = (params: IHandlerParams) => {
  provider.sendResponse(params.id, ['0x0....']);
};

provider.setHandler(handler);