javascriptpact-lang

How do I add a user of my module to the coin contract with (coin.create-account) in a way that is similar to (coin.transfer-create)?


I have a module that some users may not have any KDA in their account, and thus don't exist on the coin contract. To prove ownership of a token, I am using (enforce-guard (at "guard" (coin.details account))) which returns "with-read: row not found: k:9584f4... if the user does not exist on the coin contract.

I want to call (coin.create-account) on behalf of a user of my module, so that when I check (enforce-guard), the response is valid, and afterwards the user exists on the coin contract just like if they had received KDA in their wallet.

From my understanding, I would call coin.create-account "k:9584f4..." (read-keyset "k:9584f4...") and then pay the gas, and they would then exist on the coin contract without having any KDA. I think my problem is: Where can I get the keyset to pass into (read-keyset) if my user is calling the contract through a front-end?

More directly: where do I get the guard to pass into coin.create-account? create-account in chainweaver


Solution

  • To be able to fill out the parameters you need to define a keyset first in the ENV tab. Type a name and select a key like this:

    define keyset

    then open the module explorer and the token you want to create the account on and reference the keyset:

    create-account

    If you need to perform the same steps from code take a look at the example from the docs that does exactly that: https://docs.kadena.io/build/frontend/pact-lang-api-cookbook#create-account