Skip to content

CustomPrecompile

CustomPrecompile: Exclude<Exclude<Parameters<typeof Evm["create"]>[0], undefined>["customPrecompiles"], undefined>[number]

Custom precompiles allow you to run arbitrary JavaScript code in the EVM

Example

import { createMemoryClient } from 'tevm'
import { type CustomPrecompile } from 'tevm/evm'
import { definePrecompile, defineCall } from 'tevm'
import { createContract } from 'tevm/contract'
const precompileContract = createContract({
name: 'Precompile',
humanReadableAbi: [
'function cwd(string) returns (string)',
],
})
const customPrecompiles: CustomPrecompile = definePrecompile({
contract: precompileContract,
call: defineCall(precompileContract.abi, {
cwd: async ({ args }) => {
return {
returnValue: process.cwd(),
executionGasUsed: 0n,
}
},
}),
})
const memoryClient = createMemoryClient({ customPrecompiles: [customPrecompiles] })

See

Defined in

packages/evm/src/CustomPrecompile.ts:41