Depositing NEP5 Tokens

NEP5 tokens are deposited by invoking the exchange contract using the deposit operation and specifying the script hash (asset ID) of the token to deposit as well as the quantity of the token to deposit. An optional gas fee can be used in the transaction as well.

Invoking the contract to Deposit

Example:

import { u } from '@cityofzion/neon-js';

async function depositNep5Asset(assetId, quantity, gasFee=0) {
  await executeContractTransaction('deposit',
    [
      u.reverseHex(assetId),
      u.num2fixed8(quantity),
    ], 
    0, 0, gasFee);
}

// Deposit 1000 APH with no fee
await depositNep5Asset(
    'a0777c3ce2b169d4a23bcba4565e3225a0122d95', // APH script hash
    1000 // quantity
);

// Deposit 10000 APH with a fee of .001 GAS
await depositNep5Asset(
    'a0777c3ce2b169d4a23bcba4565e3225a0122d95', // APH script hash
    10000, // quantity
    0.001 // gas fee
);

Tokens Requiring Approval

Some tokens require approval first before they may be deposited by invoking the NEP5 extension approve operation. Here is an example of calling approve first.

Example depos

import { wallet, u, api } from '@cityofzion/neon-js';

const DEX_HASH = '9488220e8654d798f9b9cb9e74bd611ecc83fd0f';

const account = new wallet.Account(wif);

async function approveNep5Deposit(scriptHashToAllow, assetId, amount) {
  const config = {
    net: 'MainNet',
    url: 'https://mainneo.aphelion-neo.com:10331',
    script: {
      scriptHash: assetId,
      operation: 'approve',
      args: [
        u.reverseHex(wallet.getScriptHashFromAddress(account.address)),
        u.reverseHex(scriptHashToAllow),
        new u.Fixed8(amount).toReverseHex(),
      ],
    },
    fees: currentNetwork.fee,
    gas: 0,
  };

  
  config.account = account;
  const configResp = await api.doInvoke(config);
  // wait for transaction success
  await monitorTxForConfirmation(configResp.tx);
}

// deposit 100 units of asset requiring approval.
await approveNep5Deposit(DEX_HASH, '3a4acd3647086e7c44398aac0349802e6a171129', 100);
await depositNep5Asset('3a4acd3647086e7c44398aac0349802e6a171129', 100)