Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of tokens from within other canister #2

Open
moritz-schindelmann opened this issue Jul 10, 2021 · 3 comments
Open

Usage of tokens from within other canister #2

moritz-schindelmann opened this issue Jul 10, 2021 · 3 comments

Comments

@moritz-schindelmann
Copy link

I'm struggling to figure out how to use the token examples / standards within other canisters.

Scenario: I want to create a token not from a frontend, but another "backend" canister instead.

Expected behavior:

I can deploy my canister with the token standard as a dependency and create new tokens whenever I want.

I configured my test env like this:

...
"canisters": {
    "erc20": {
      "main": "src/token_test/assets/examples/erc20.mo",
      "type": "motoko"
    },
    "token_test": {
      "main": "src/token_test/main.mo",
      "type": "motoko",
      "dependencies": ["erc20"]
    }
  },
...

Actual behavior:

Dfinity fails with "Invalid data: Expected arguments but found none.".
To my understanding, this happens because the tokens are defined as actors so that they can be deployed on their own. But in my case, this throws an error because dfinity tries to deploy the erc20 dependency (which would create a token).

Now I understand I can remove the "actor" and just use the token as a class, but I don't know if that is the desired behavior here.

What do you suggest?

@stephenandrews
Copy link
Contributor

So remove the dep and remove erc20 as a canister - anything listed in the canister section defines one to be created. So your json should just be:

...
"canisters": {
    "token_test": {
      "main": "src/token_test/main.mo",
      "type": "motoko"
    }
  },
...

Then in main.mo include the erc20.mo file as an import, e.g.:

import ERC20 "./assets/examples/erc20";

and then to create the token in code you would do something like:

let name : Text = "My Token";
let symbol : Text = "MYT";
let decimals : Nat8 = 2;
let supply : Nat = 10000;
let token = await ERC20.erc20_token(name, symbol, decimals, supply, msg.caller);

We recommend using the multi-canister approach due to cost savings. Currently it cost about 1T cycles to originate a new canister, where as the multi-canister approach costs about 50M cycles per token.

@stephenandrews
Copy link
Contributor

I'll look to add an example of this soon too

@moritz-schindelmann
Copy link
Author

moritz-schindelmann commented Jul 11, 2021

Thank you! I got a couple of steps further with your help. But a full example with usage etc. would be very helpful. I think it would help a lot of new ic devs that are trying to get into motoko & tokens if they can kickstart without fighting through the motoko documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants