TransWikia.com

How do I call the FA2 balance_of endpoint through Truffle?

Tezos Asked on August 19, 2021

I have written a contract to implement FA2 and I have a Truffle/JavaScript setup to test this contract while running against a sandboxed node. I can test the transfer endpoint and the update_operators endpoint, but I don’t know how to construct the right JavaScript object to test the balance_of or the token_metadata_registry endpoint.

The input value as defined in LIGO (Pascal dialect) to token_metadata_registry is:

type token_metadata_registry_parameter is contract(address);

The input type to the balance_of endpoint is balance_of_parameter_michelson defined as

type balance_of_request is record
    owner: token_owner;
    token_id: token_id;
end;

type balance_of_response is record
    request: balance_of_request;
    balance: token_balance;
end;

type balance_of_callback is contract(list(balance_of_response));

type balance_of_parameter is record
    requests: list(balance_of_request);
    callback: balance_of_callback;
end;

type balance_of_request_michelson is michelson_pair_right_comb(balance_of_request);

type balance_of_response_auxiliary is record [
    balance: token_balance;
    request: balance_of_request_michelson;
]

type balance_of_response_michelson is michelson_pair_right_comb(balance_of_response_auxiliary);

type balance_of_callback_michelson is contract(list(balance_of_response_michelson));

type balance_of_parameter_auxiliary is record [
    requests: list(balance_of_request_michelson);
    callback: balance_of_callback_michelson;
]

type balance_of_parameter_michelson is michelson_pair_right_comb(balance_of_parameter_auxiliary);

One Answer

As far as I know, you cannot check if the entrypoint returns the balance with JavaScript, because the entrypoint doesn't return a value but emits a transaction. I didn't try it for a FA2 token contract but to test a FA1.2 token contract with Truffle, I wrote a simple contract that would call the FA1.2 balance_of entrypoint and receive the balance on a different entrypoint before saving it in its storage. I would then fetch the storage of this contract to verify that the balance is what was expected.

Correct answer by Claude Barde on August 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP