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:

1 Like

That’s right I saw it then too. That’s why I wanted to continue with this one: extendable-token/standard.mo at main · ICPSwap-Labs/extendable-token · GitHub

I managed to import the modules mo:cap and mo:ic-commons. However, now I have 3 more errors:

@cryptoschindler

I’m not sure what you are trying to do, but the VSCode extension basically tells you what the problem is. You are for example trying to use TokenIdentifier, but there is no definition of what that is. You can either import the type from another module or redefine it.

Yes, you are right thank you! The only thing i cant solve is this error above (i edited the picture). I dont understand where i need to implement this.I declared this type.

    type TransferRequest = ExtCore.TransferRequest;

I dont know what im missing

Again the compiler is your friend and basically tells you that the nonce field you are referring to in the transfer.nonce does not exist in the type TransferRequest. And indeed, when you check the type definition you can see that it’s missing

You can either implement it yourself or open an issue in the repository. I haven’t checked it thoroughly but it looks like a bug that it’s missing.

I have implemented it now, thank you. Now I don’t have any errors in the code and I was able to deploy it locally. Unfortunately just not on the right network with --network ic

I get this error:

Im using this query

dfx deploy --network=ic --wallet="mpza4-jiowq-w3pxl-4qxoc-iy4lo-aq4o2-si3cl-nghcq-mmmyi-ftri6-3qe" --argument='("TOKEN", "$TOKEN", 2, 100000:nat, principal "principal id i removed for forum")' --with-cycles 1500000000000

Canister ID of my wallet

dfx identity --network ic get-wallet 

hoysn-3aaaa-aaaan-qazqa-cai

Principal ID of my wallet

dfx identity --network ic get-principal
moztx-lv47l-qf53e-miy6s-pcp2k-6k5ya-xbsw2-mvxvy-vsmd6-k5kqj-cae

Status of my canister

Canister status call result for standard.
Status: Running
Controllers: moztx-lv47l-qf53e-miy6s-pcp2k-6k5ya-xbsw2-mvxvy-vsmd6-k5kqj-cae
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 2_592_000
Memory Size: Nat(8056313)
Balance: 2_025_410_846_708 Cycles
Module hash: 0xbb001d1ebff044ba43c060956859f614963d05c77bd778468fce4de095fe8f92

I tried out a lot and looked in the forum but nothing helped. What do I have to do to solve the error? If you need more informations let me know.

You have to pass your wallet’s canister ID into the --wallet flag

1 Like

I looking at the controllers of the canister I think he should omit the wallet flag entirely as it looks like his idenity is already the sole controller of the canister.

1 Like

I tried --wallet with canister ID already and it didn’t work.

Omitting the flag has helped me. This error followed

I could solve it with

dfx canister --network ic install --mode reinstall --argument='("TOKEN", "$TOKEN", 2, 100000:nat, principal "principal id i removed for forum")' standard

It finally worked. Many thanks!

2 Likes

The only thing I still have problems with is the setLogo() function

dfx canister --network=ic call standard setLogo '("")'.

The function expects a text parameter.

I have tried it now like this:

dfx canister --network=ic call standard setLogo '("data:image/png;base64, base64code")' 
dfx canister --network=ic call standard setLogo '("1.png")
dfx canister --network=ic call standard setLogo '("../1.png")
dfx canister --network=ic call standard setLogo '("imagehosturl")

I do not get any error. On ICScan the text is shown but when I want to add my token to plug wallet it still doesn’t show a logo.

Truly my last question now. What am I doing wrong?

Base64 encoded text should be fine. IDK if plug surfaces the logo from the canister or if it comes from DAB. Maybe @oss

1 Like