1- import { decodeFunctionResult , encodeFunctionData } from "viem" ;
1+ import { decodeFunctionResult , encodeFunctionData , type Abi } from "viem" ;
22
33import { getFlagBoolean , getFlagString } from "../args" ;
44import { parseAbiFile } from "../abi" ;
@@ -127,6 +127,11 @@ export async function runOnchainSendWithFunction(
127127 ctx : CommandContext ,
128128 forcedFunctionName ?: string ,
129129 commandOverride ?: string ,
130+ defaults ?: {
131+ abi ?: Abi ;
132+ address ?: `0x${string } `;
133+ source ?: string ;
134+ } ,
130135) : Promise < JsonValue > {
131136 const config = loadConfig ( ) ;
132137 const profileName = getFlagString ( ctx . args . flags , "profile" ) || ctx . globals . profile ;
@@ -136,10 +141,31 @@ export async function runOnchainSendWithFunction(
136141 const chain = resolveChain ( profile . chain ) ;
137142 const rpcUrl = resolveRpcUrl ( chain , getFlagString ( ctx . args . flags , "rpc-url" ) || profile . rpcUrl ) ;
138143
139- const abiFile = requireFlag ( getFlagString ( ctx . args . flags , "abi-file" ) , "--abi-file" ) ;
140- const abi = parseAbiFile ( abiFile ) ;
141-
142- const address = parseAddress ( getFlagString ( ctx . args . flags , "address" ) , "--address" ) ;
144+ const abiFile = getFlagString ( ctx . args . flags , "abi-file" ) ;
145+ const abi = abiFile
146+ ? parseAbiFile ( abiFile )
147+ : defaults ?. abi ||
148+ ( ( ) => {
149+ throw new CliError ( "MISSING_ARGUMENT" , "--abi-file is required." , 2 , {
150+ command : commandOverride || ctx . commandPath . join ( " " ) ,
151+ hint : forcedFunctionName
152+ ? "This mapped command has no built-in ABI metadata yet. Provide --abi-file."
153+ : "Provide --abi-file <path>." ,
154+ } ) ;
155+ } ) ( ) ;
156+
157+ const addressInput = getFlagString ( ctx . args . flags , "address" ) ;
158+ const address = addressInput
159+ ? parseAddress ( addressInput , "--address" )
160+ : defaults ?. address ||
161+ ( ( ) => {
162+ throw new CliError ( "MISSING_ARGUMENT" , "--address is required." , 2 , {
163+ command : commandOverride || ctx . commandPath . join ( " " ) ,
164+ hint : forcedFunctionName
165+ ? "This mapped command has no built-in contract address yet. Provide --address."
166+ : "Provide --address <0x...>." ,
167+ } ) ;
168+ } ) ( ) ;
143169 const functionName = forcedFunctionName || requireFlag ( getFlagString ( ctx . args . flags , "function" ) , "--function" ) ;
144170 const args = parseArgsJson ( getFlagString ( ctx . args . flags , "args-json" ) ) ;
145171
@@ -197,6 +223,11 @@ export async function runOnchainSendWithFunction(
197223 address,
198224 functionName,
199225 args,
226+ defaults : {
227+ abi : abiFile ? "flag" : defaults ?. abi ? "mapped-default" : "none" ,
228+ address : addressInput ? "flag" : defaults ?. address ? "mapped-default" : "none" ,
229+ source : defaults ?. source || null ,
230+ } ,
200231 result,
201232 } ;
202233}
0 commit comments