transactionstokenactiontransfernearprotocol

How to transfer non-native token on NEAR blockchain


I'm struggling to transfer token with tokenAddress "meta-token.near" from wallet A to wallet B. I can't provide you with one of my solutions, cause the all don't work. Any help is appreciated. Thanks in advance!

So to create a transaction of transfer of NEAR I used this: transaction = nearAPI.transactions.createTransaction( from, publicKey, to, nonce, actions, recentBlockHash );

I guess to transfer meta-token.near I need to do make specific actions. I tried to implement functionCall but failed.

UPDATE:

If I send tokens right from wallet, two methods get called: https://nearscan.org/transactions/GTPxHnazxwH5hNzsMhd9WKe1GHEjecpkJowUzqKoitWr https://nearscan.org/transactions/55bxoftL7fvnTw4Vth61SYp9BKoBTinkESXGUscR6xwa


Solution

  • I found a way to do this:

    const actions3 = [
      nearAPI.transactions.functionCall(
        "storage_deposit",
        Buffer.from(JSON.stringify({ "account_id": to })),
        MAX_GAS,
        deposit
      ),
      nearAPI.transactions.functionCall(
        "ft_transfer", 
        Buffer.from(JSON.stringify({ "receiver_id": to, "amount": amount })),
        MAX_GAS,
        1
      )
    ];