Skip to content

Instantly share code, notes, and snippets.

@macelai
Created September 8, 2022 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macelai/911026c8397681bf50b5de9094eaab0f to your computer and use it in GitHub Desktop.
Save macelai/911026c8397681bf50b5de9094eaab0f to your computer and use it in GitHub Desktop.
return new Promise((_, rej) => {
const provider = webSocketProvider()
//@ts-ignore
provider.on('error', e => rej(e))
const web3 = new Web3(provider)
try {
var contract = new web3.eth.Contract(signaturesAbi, SIGNATURES_CONTRACT)
contract.events
.NewMigration({ fromBlock: verifiedSignatureLatestBlock }, handleEvent)
.on('error', (event: any) => debug.error(event, 'error on signature event'))
} catch (error) {
rej(error)
}
})
@fernandobt8
Copy link

the webSocketProvider function is missing

export function webSocketProvider() {
  return new Web3.providers.WebsocketProvider(WEB3_WEBSOCKET_PROVIDER!, {
    timeout: 5000,

    clientConfig: {
      //ping to keep the connection alive
      keepalive: true,
      keepaliveInterval: 5000, // ms

      //ping timeout in case of connection problems
      dropConnectionOnKeepaliveTimeout: true,
      keepaliveGracePeriod: 5000, // ms
    },

    //try to connect again
    reconnect: {
      auto: true,
      delay: 5000, // ms
      maxAttempts: 5,
      onTimeout: false,
    },
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment