Unable to pass dfx text output to an argument that needs Candid encoded values

I have a canister that relies on arguments passed at initialization to pass values into the init function. I’m trying to Candid encode the values but running into the following:
image

This is what the Candid argument looks like
image

Basically the error is “Text must be in valid Base32 encoding”.

What am I doing wrong?

P.S. If I echo that command, I get a valid principal ID. Like this

Shells only do command interpolation (that’s what this is called) if you are in a "..." string, but you’re in a '...' string. If you use " around your argument, it will work. But you’ll have to escape the " in the string itself

1 Like

@Severin
So, like this?

"\"$(dfx identity get-principal)\""

or this?

\""$(dfx identity get-principal)"\"

Let me try both :slight_smile:

Neither worked

image

image

I think I misunderstood what you explained.

Candid expects this:

(principal "aaaaa-aa")

Converting to '...' string (because the shell will interpret the above as two separate tokens):

'(principal "aaaaa-aa")'

Converting to "..." string:

"(principal \"aaaaa-aa\")"

Using interpolation:

"(principal \"$(dfx canister id user_index)\")"
1 Like

So, after rereading what you said, I think I get it.

For anyone reading after, this is what the solution looks like:
image

1 Like