0

I'm trying to call an FA1.2 transfer function from another contract. Here is my endpoint in the FA1.2 contract:

type action is
| Transfer of michelson_pair(address, "from", michelson_pair(address, "to", nat, "value"), "")
...


function main (const p : action ; const s : storage) : (list(operation) * storage) is
block {
   if amount =/= 0tz then failwith ("This contract does not accept tezi deposits"); else skip;
  } with case p of
  | Transfer(n) -> ((nil : list(operation)), transfer(n.0, n.1.0, n.1.1, s))
  | Approve(n) -> ((nil : list(operation)), approve(n.0, n.1, s))
  | GetBalance(n) -> (get_balance(n.0, n.1, s), s)
  | GetAllowance(n) -> (get_allowance(n.0.0, n.0.1, n.1, s), s)
  | GetTotalSupply(n) -> (get_total_supply(n.1, s), s)
end

Here is how I try to call the contract. I define a type to call it:

type transfer_action is Transfer of michelson_pair(address, "from", michelson_pair(address, "to", nat, "value"), "")

and I try to get the entrypoint like this:

const token_contract: contract(transfer_action) = case (Tezos.get_entrypoint_opt("%transfer", storage.token_address): option(contract(transfer_action))) of
  | Some (c) -> c
  | None -> (failwith("incorrect contract") : contract(transfer_action))
end;

The call always fails with "incorrect contract". Calling GetBalance for example works, but Approve and Transfer do not. I also tried "%transfer" and "%Transfer".

3
  • Could you link to the full contract (or an minimal but still compilable version), for both the callee and the called contract?
    – arvidj
    Feb 18 at 16:59
  • well I built a minimal version and it works there haha. I'll have to check what I'm doing wrong then. Feb 18 at 23:34
  • @arvidj I figured out how to fix the issue, I posted this as the answer below. Take a look if you have time. Feb 19 at 1:53
0

So I figured out a solution, I don't know why this works but it does (or why it doesn't work without the solution).

The contract I'm trying to trigger transfers from is an FA2 token contract. I need to define the transfer_action type before I import the fa2 type declarations

type transfer_action is TransferAction of michelson_pair(address, "from", michelson_pair(address, "to", nat, "value"), "")

#include "../../../partials/fa2/fa2_types.ligo"

inside the types declaration file I define the type to call the balance_of function:

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

type balance_of_request_michelson is michelson_pair_right_comb(balance_of_request);

for whatever reason the balance_of_request_michelson type declaration makes the fetching of the transfer entrypoint fail. If anyone knows why that happens, please share.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.