Quiero inyectar un proveedor (window.ethereum) que pueda hacer que ethers.js web3.js funcione en flutter WebView
Ahora he implementado la primera versión, pero no funciona y no puede ser reconocido por ethers.js o Web3.js
Aquí está mi código
enum RpcMethods { eth_requestAccounts = "eth_requestAccounts", } interface RequestArguments { method: RpcMethods; params?: unknown[] | object; } function _request({ method, params }: RequestArguments): Promise<any> { return _sendToFlutter(method, params); } function _connect({ method, params }: RequestArguments): Promise<any> { return _sendToFlutter(method, params); } function _disconnect({ method, params }: RequestArguments): Promise<any> { return _sendToFlutter(method, params); } function _isConnected({ method, params }: RequestArguments): Promise<any> { return _sendToFlutter(method, params); } function _sendToFlutter(rpcMethod: RpcMethods, params?: any) { return (<any>globalThis).flutter_inappwebview.callHandler(rpcMethod, params); } (<any>globalThis).ethereum = { request: _request, connect: _connect, disconnect: _disconnect, isConnected: _isConnected, };Contrato de llamada
const callContract = async () => { const contract = new ethers.Contract( "0x27998293A37A0662389487214d1cF37E1B319fe3", "Contract Abis", new ethers.providers.Web3Provider((window as any).ethereum, { name: "ETD", chainId: 3101, }).getSigner() ); const res = await contract.functions.getRecentTokens(); alert(JSON.stringify(res)); }mensaje de error:
Uncaught (in promise) TypeError: Cannot read property 'length' of null