getMainnet.js 487 B

1234567891011121314151617181920
  1. import { mainNetMap } from './contract'
  2. export async function getMainnet () {
  3. let promiseAll = []
  4. for (let i in mainNetMap) {
  5. let p1 = new Promise((resolve, reject) => {
  6. let mainnet = mainNetMap[i]
  7. fetch(`https://${mainnet}/v1/chain/get_info`)
  8. .then(data => {
  9. resolve(mainnet)
  10. })
  11. .catch(error => {
  12. reject(error)
  13. })
  14. })
  15. promiseAll.push(p1)
  16. }
  17. let result = await Promise.race(promiseAll)
  18. return result
  19. }