Provider.createEmitter
Creates an EIP-1193 flavored event emitter to be injected onto a Provider.
Imports
Named
import { Provider } from 'ox'
Examples
import { Provider, RpcRequest, RpcResponse } from 'ox'
// 1. Instantiate a Provider Emitter.
const emitter = Provider.createEmitter()
const store = RpcRequest.createStore()
const provider = Provider.from({
// 2. Pass the Emitter to the Provider.
...emitter,
async request(args) {
return await fetch('https://1.rpc.thirdweb.com', {
body: JSON.stringify(store.prepare(args)),
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then((res) => res.json())
.then(RpcResponse.parse)
},
})
// 3. Emit Provider Events.
emitter.emit('accountsChanged', ['0x...'])
Definition
function createEmitter(): Emitter
Source: src/Provider.ts
Return Type
An event emitter.