-
is there a ready way to get args with keys at once? // "tokenId" | "reciever"
type Names = MintAbi['inputs'][number]['name']
// readonly [`0x${string}`, bigint]
export type MintAbiArgs = AbiParametersToPrimitiveTypes<MintAbi['inputs']> like: export type MintAbiArgsObject = {
tokenId: `0x${string}`
reciever: bigint
} ideally zod helper: export const mintInputSchema = z.object({
tokenId: Address,
reciever: z.bigint(),
}) |
Beta Was this translation helpful? Give feedback.
Answered by
tmm
Jan 31, 2024
Replies: 1 comment
-
You can do something like this: import {
type AbiParameter,
type AbiParameterKind,
type AbiParameterToPrimitiveType,
} from 'abitype'
type AbiParametersToPrimitiveTypes<
abiParameters extends readonly (AbiParameter & { name: string })[],
abiParameterKind extends AbiParameterKind = AbiParameterKind,
> = {
[name in abiParameters[number]['name']]: AbiParameterToPrimitiveType<
Extract<abiParameters[number], { name: name }>,
abiParameterKind
>
}
type Result = AbiParametersToPrimitiveTypes<
// ^? type Result = { sender: `0x${string}`; recipient: `0x${string}`; amount: bigint; }
[
{ name: 'sender'; type: 'address' },
{ name: 'recipient'; type: 'address' },
{ name: 'amount'; type: 'uint256' },
]
> Note that |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
reslear
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do something like this:
TypeScript Playground