Creating Offers

Offers can be created by sending a Neo invocation transaction that invokes the addOffer operation. Creating an offer supports the use case of creating a limit order.

Note that the use create of performing a market order requires accepting one or more offers and is not covered in this section.

Creating a limit order by creating an offer.

Creating a limit order is performed by sending a contract transactions with the details of the order. As long as the account creating the transaction has enough contract balance available to lock the funds, then the transaction will succeed and the order will be created.

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

async function createOffer(assetIdToBuy, quantityToBuy, assetIdToSell, quantityToSell, neoToSend, gasToSend) {
  const transaction = await buildContractTransaction('addOffer',
    [
      u.reverseHex(assetIdToBuy),
      u.num2fixed8(quantityToBuy),
      u.reverseHex(assetIdToSell),
      u.num2fixed8(quantityToSell),
      u.num2fixed8(nonce),
    ], neoToSend, gasToSend);

  return tx.serializeTransaction(transaction.tx, true);
}

Example Create Offer, send, and wait

The offer can be posted directly to the blockchain or through the API.

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

const APH_ASSET_ID =  'a0777c3ce2b169d4a23bcba4565e3225a0122d95';
const NEO_ASSET_ID = '';

const nonce = new Date().getTime() * 0.00000001;
var configResponse = await createOffer(APH_ASSET_ID, 1000, NEO_ASSET_ID, 10, nonce, 10, 0);
await api.sendTx(configResponse);
await monitorTxForConfirmation(configResponse.tx);