1

I'm developing a Flutter application and used Dartez plugin to transfer token contracts from one wallet to another wallet.

The Dartez package has a function named sendContractInvocationOperation for this purpose.

I used this function in my project like this:

final token = TokenModel(...);
var server = '';

var keyStore = KeyStoreModel(
      publicKey: 'edpk.....rrj',
      secretKey: 'edsk.....yHH',
      publicKeyHash: 'tz1.....hxy',
    );
int amount = 10000; // just as sample
String withdrawalAddress = "tz1.....xyz";

var signer = await Dartez.createSigner(
        Dartez.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var contractAddress = ['KT1.....xMY'];

final parameters = token.isFA1
          ? '''(Pair "${keyStore.publicKeyHash}" (Pair "$withdrawalAddress" $amount))'''
          : '''{Pair "${keyStore.publicKeyHash}" {Pair "$withdrawalAddress" (Pair $tokenId $amount)}}''';

      final dynamic resultInvoke = await Dartez.sendContractInvocationOperation(
        server,
        signer as SoftSigner,
        keyStore,
        contractAddress,
        [0],
        customFee,
        1000,
        customFee,
        ['transfer'],
        [parameters],
        codeFormat: TezosParameterFormat.Michelson,
      );

print("Operation groupID ===> $resultInvoke['operationGroupID']");

But the problem is when my token standard is "fa2" then the transaction failed with this error: please click here to see the error log

The above error was about the Crunch token, which is a token with the "fa2" standard.

I also checked the transfer function entypoints from here: CRUNCH entypoints and the transfer function is:

Json schema:
"schema:list:object": [
    {
        "from_:address": "address",
        "txs:list:object": [
            {
                "to_:address": "address",
                "token_id:nat": "nat",
                "amount:nat": "nat"
            }
        ]
    }
]
Michelson type:
(list %transfer (pair (address %from_)
                     (list %txs (pair (address %to_) (pair (nat %token_id) (nat %amount))))))

As you see, it provides the function in Michelson type, but I'm not sure whether the parameters that I retrieved from this Michelson function and used inside "Dartez.sendContractInvocationOperation" function is the correct format or not.

Note: I don't understand the Michelson language and don't know the correct syntax.

2 Answers 2

3

I don't know Dart, Flutter, or this library so my help will be limited. From looking at your code you have 2 sets of Michelson that is decided based on whether its FA1 or 2

final parameters = token.isFA1
          ? '''(Pair "${keyStore.publicKeyHash}" (Pair "$withdrawalAddress" $amount))'''
          : '''{Pair "${keyStore.publicKeyHash}" {Pair "$withdrawalAddress" (Pair $tokenId $amount)}}''';

Crunch is an FA2 token, so it should be the second set, which would send 4 pieces of data:

  • Source address
  • Destination Address
  • TokenID
  • Amount to send

Taking a look at the TzKT link you sent and clicking the button to view the raw operation JSON, I can see that only 3 pieces of data was sent:

  • Source address
  • Destination Address
  • Amount to send

enter image description here

It looks like your token.isFA1 code is broken to me

2
  • Thanks for answering me. I found my problem was about something else. The parameters which I passed were correct. I also learned from your answer.
    – Taleb
    Aug 26, 2022 at 15:18
  • @Taleb they were not ;) look at my answer
    – Groxan
    Aug 26, 2022 at 15:35
2

In addition to @simon-mcloughlin's answer, if you don't know how to build Michelson parameters you can use a helper endpoint in TzKT API: https://api.tzkt.io/#operation/Contracts_BuildEntrypointParametersGET

So, looking at the JSON schema on TzKT:

"schema:list:object": [
    {
        "from_:address": "address",
        "txs:list:object": [
            {
                "to_:address": "address",
                "token_id:nat": "nat",
                "amount:nat": "nat"
            }
        ]
    }
]

your parameters (in JSON format) should look like this:

[
    {
        "from_": "tz1LK2aE2zmvqqsVYGAaCTauz7peWQ3gAuqK",
        "txs": [
            {
                "to_": "tz1NJrXkEhwcqNxkARvb44psCCb4VyJ4Qh1b",
                "token_id": "0",
                "amount": "100000000"
            }
        ]
    }
]

Then, just pass it to the API: https://api.tzkt.io/v1/contracts/KT1BHCumksALJQJ8q8to2EPigPW6qpyTr7Ng/entrypoints/transfer/build?value=[{%22from_%22:%22tz1LK2aE2zmvqqsVYGAaCTauz7peWQ3gAuqK%22,%22txs%22:[{%22to_%22:%22tz1NJrXkEhwcqNxkARvb44psCCb4VyJ4Qh1b%22,%22token_id%22:%220%22,%22amount%22:%22100000000%22}]}]

and here is the result:

[
  {
    "prim": "Pair",
    "args": [
      {
        "bytes": "000007601f902f440e65f9e1acb29c8a361a65ba70f2"
      },
      [
        {
          "prim": "Pair",
          "args": [
            {
              "bytes": "00001d47fdd96fb5cc1141cbed92ef36d82515a69053"
            },
            {
              "prim": "Pair",
              "args": [
                {
                  "int": "0"
                },
                {
                  "int": "100000000"
                }
              ]
            }
          ]
        }
      ]
    ]
  }
]

This is what you should specify in the transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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