Dfx argument examples

Because it isn’t something I do that often, it always takes me lots of time to figure out how to encode arguments with dfx when I work on my projects. Is there a comprehensive repo or blog posts somewhere that summarize and showcase most common examples?

The only thing that comes to my mind is the Candid reference, which contains examples for everything I ever needed. Do you miss anything in particular from this page?

Thanks for the answer but, yes it isn’t what I am looking for. This is more a documentation, I really meant comprehensive examples or blog posts.

I see. I don’t know anything like that, sorry.

1 Like

Hello @peterparker, can you please explain what examples you are looking for?

Are you looking for an example of how to pass an argument for each type in the Candid reference?

I guess I was looking for code snippet of bash scripts. I don’t really need those anymore, my question is a year old. Any particular reason why you are asking?

Yes, we are creating documentation examples: Docs Dev Accelerator: Add 'Pass a variant and array as an argument' doc by jennifertrin · Pull Request #2499 · dfinity/portal · GitHub.

We are starting with variant and array but curious if there were other types that were challenging to work with.

1 Like

Note that in the next dfx release, we will have the Candid assist feature: when you don’t know how to type a Candid argument in dfx canister call, simply skip the argument in the command line, and dfx will prompt for necessary information to generate the argument.


Looking forward to seeing the feature. Will take note and update the docs accordingly when it is released

Something I’ve found difficult to work with was blobs, particularly when trying to take hex and convert it into the expected format with every byte separated by \.

I had to write a script like this to upload a WASM binary to a canister:


WASM_HEX=$(xxd -p -u ${WASM_FILE} | tr -d '\n')
echo "(blob \"${WASM_HEX}\")" > ${ARG_FILE}

dfx canister call --update dashboard_api ${MTHD} --argument-file ${ARG_FILE}

@chenyan will the Candid assist feature have anything to help with uploading files like this?


It helps to some extend. For blob type, you can input either 1) the original format; 2) hex string; 3) load from a file. But there is still no good way to do this in script.

One idea is to integrate ic-repl in dfx, so that we can use file("a.wasm") to load the blob in script.

1 Like

Thanks, I look forward to trying it out. If it accepts these formats, I think I won’t need a script anymore anyway.