Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Use dos proveedores al mismo tiempo (uno Ethereum, otro — Polygon)

Me gustaría usar dos proveedores al mismo tiempo, uno es Web3Proivder, que obtengo a través de la conexión Metamask, y funciona bien. Estoy atascado en la configuración del proveedor de Polygon en este momento. Quiero leer los datos del almacenamiento de los contratos de Polygon, ¿cómo hago eso?

Este es el código que funciona:

 function callWithActiveProvider() { const { library, account, chainId } = useActiveWeb3React(); const contract: Contract | null = useMemo(() => getCollectContract(library, account, chainId), [ library, account, chainId, ]); contract.callSomeMethod(); } callWithActiveProvider(); // this works

Esto no lo hace:

 function callWithPolygonProvider() { const { library, account, chainId } = ???????(); const contract: Contract | null = useMemo(() => getCollectContract(library, account, chainId), [ library, account, chainId, ]); contract.callPolygonMethod(); } callWithPolygonProvider() // but how do I do this?

Estas son las funciones/importaciones que se usan arriba:

 import { useWeb3React, useWeb3React as useWeb3ReactCore } from '@web3-react/core'; function getSigner(library: Web3Provider, account: string): JsonRpcSigner { return library.getSigner(account).connectUnchecked(); } function getProviderOrSigner( library: Web3Provider, account?: string, ): Web3Provider | JsonRpcSigner { return account ? getSigner(library, account) : library; } function getContract( address: string, ABI: any, library: Web3Provider, account?: string, ): Contract { if (!isAddress(address) || address === AddressZero) { throw Error(`Invalid 'address' parameter '${address}'.`); } return new Contract(address, ABI, getProviderOrSigner(library, account) as any); } function useActiveWeb3React(): Web3ReactContextInterface<Web3Provider> & { chainId?: ChainId; } { const context = useWeb3ReactCore<Web3Provider>(); const contextNetwork = useWeb3ReactCore<Web3Provider>(NetworkContextName); return context.active ? context : contextNetwork; } function getCollectContract(library: Web3Provider, account: string, chainId: ChainId) { return getContract(CONTRACT_ADDRESS, CONTRACT_ABI, library, account); }

La parte más difícil es que ambos deberían funcionar al mismo tiempo, para que el usuario pueda realizar una transacción en Ethereum, y deberíamos poder realizar una solicitud para leer el almacenamiento del contrato de Polygon en segundo plano.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Probablemente desee un segundo web3 con una URL https de polígono de infura:

 const Web3 = require('web3') const polygonWeb3 = new Web3(new Web3.providers.HttpProvider(infuraUrl))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!