MCPcopy Create free account
hub / github.com/wevm/viem / encodeErrorResult

Function encodeErrorResult

src/utils/abi/encodeErrorResult.ts:68–96  ·  view source on GitHub ↗
(
  parameters: EncodeErrorResultParameters<abi, errorName>,
)

Source from the content-addressed store, hash-verified

66 | ErrorType
67
68export function encodeErrorResult<
69 const abi extends Abi | readonly unknown[],
70 errorName extends ContractErrorName<abi> | undefined = undefined,
71>(
72 parameters: EncodeErrorResultParameters<abi, errorName>,
73): EncodeErrorResultReturnType {
74 const { abi, errorName, args } = parameters as EncodeErrorResultParameters
75
76 let abiItem = abi[0]
77 if (errorName) {
78 const item = getAbiItem({ abi, args, name: errorName })
79 if (!item) throw new AbiErrorNotFoundError(errorName, { docsPath })
80 abiItem = item
81 }
82
83 if (abiItem.type !== 'error')
84 throw new AbiErrorNotFoundError(undefined, { docsPath })
85
86 const definition = formatAbiItem(abiItem)
87 const signature = toFunctionSelector(definition)
88
89 let data: Hex = '0x'
90 if (args && args.length > 0) {
91 if (!abiItem.inputs)
92 throw new AbiErrorInputsNotFoundError(abiItem.name, { docsPath })
93 data = encodeAbiParameters(abiItem.inputs, args)
94 }
95 return concatHex([signature, data])
96}

Callers 8

getEnsName.test.tsFile · 0.85
getEnsText.test.tsFile · 0.85
ccip.test.tsFile · 0.85
encodeErrorFunction · 0.85
errors.test.tsFile · 0.85

Calls 5

getAbiItemFunction · 0.85
formatAbiItemFunction · 0.85
toFunctionSelectorFunction · 0.85
encodeAbiParametersFunction · 0.85
concatHexFunction · 0.85

Tested by

no test coverage detected