The Replica returned an error: code 5, message: "Canister trapped explicitly: assertion failed"

Hello everyone,

im trying to deploy a token contract motoko-token/token.mo at master · ccyanxyz/motoko-token · GitHub on the internet computer. When using:

dfx canister call token transfer "($OWNER, 10)"

This error comes up:

Error: Failed update call.
Caused by: Failed update call.
The Replica returned an error: code 5, message: "Canister trapped explicitly: assertion failed at main.mo:27.9-27.28"

Can anyone help me with that? Thanks in advance!

Looks like you have to call initialize first.

1 Like

I did not put in my code but only the repository. I have declared all variables and I thought that should work directly with the deploy. The problem still exists even if I call the init function again in the UI or via the terminal. The init function gives me the same error. Its working offline but not online.

By offline I assume you mean locally?

If you want to call your canister that is deployed to the mainnet, use the following flag

dfx canister call --network ic token transfer "($OWNER, 10)"

Make sure you called initalize before as well. Calling initialize more then once is supposed to throw an error, so that’s expected. See the assert statement:

1 Like

Yes i mean locally.

So i called initialize only once and it still throws an error and it doesnt initialize my variables:

dfx canister --network ic call token initialize '("test", "dasda", 3124141, 0)'

dfx canister --network ic call token transfer "($OWNER, 10)"

It returns

Error: Failed update call.
Caused by: Failed update call.
 The Replica returned an error: code 5, message: "Canister trapped explicitly: assertion failed at main.mo:17.9-17.37"

When i use
dfx canister --network ic call token name

It returns

("")

When i use

dfx canister call token name

It returns the name

("test")

can you try the following, note that this will delete all state in your production canister!

dfx deploy --network ic --mode reinstall

dfx canister --network ic call token initialize '("test token", "tt", 0, 1000)'

// should return "test token"
dfx canister --network ic call token name

// should remove 10 tokens from the calling identity and add 10 to $OWNER 
dfx canister --network ic call token transfer "($OWNER, 10)"

for your call to initalize i think you mixed up the position for the decimals and the total supply.

1 Like

I dont know why but it didnt work. Im trying a different github project now because this seems more advanced as well: GitHub - rocklabs-io/ic-token: DIP20: A fungible token standard for the DFINITY Internet Computer. New repo: https://github.com/Psychedelic/DIP20

Now im getting this error:

So i paste a picture in base64 code but didnt work as well

This happens to me when I make the last step in the read me (ic-token/README.md at main · rocklabs-io/ic-token · GitHub)

I looked on the solutions here on the forum but they didnt help me

@cryptoschindler

1 Like

I don’t think you have to escape the double quotes with a backslash because you are using single quotes to encapsulate the argument, this should be the reason for the candid parser error you are seeing.

1 Like

First I wanted to thank you so much for the help you give me! The whole thing worked after your hint.

I am currently deploying an Extandable Token. extendable-token/erc20.mo at main · ICPSwap-Labs/extendable-token · GitHub

I have now deployed the token live. Now I wonder how I can add an image to the token? With the DIP-20 token it was easy with the parameters with base64 but here I don’t understand it. Do you know how I can implement this?

@cryptoschindler

There’s no specification of the encoding of the symbol as far as I can see :confused: