Skip to content

createHttpHandler

createHttpHandler(client): RequestListener<typeof IncomingMessage, typeof ServerResponse>

/**

  • Creates a Node.js http handler for handling JSON-RPC requests with Ethereumjs EVM
  • Any unimplemented methods will be proxied to the given proxyUrl
  • This handler works for any server that supports the Node.js http module

Parameters

client: Client

Returns

RequestListener<typeof IncomingMessage, typeof ServerResponse>

Throws

Example

* import { createHttpHandler } from 'tevm/server'
* import { createTevm } from 'tevm'
* import { createServer } from 'http'
*
* const PORT = 8080
*
* const tevm = createTevm({
* fork: {
* transport: http('https://mainnet.optimism.io')({})
* }
* })
*
* const server = createServer(
* createHttpHandler(tevm)
* )
* server.listen(PORT, () => console.log({ listening: PORT }))
*

Defined in

packages/server/src/createHttpHandler.js:37