npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zecrey/zecrey-client-core

v1.0.33

Published

Zecrey Client Core Modules

Downloads

28

Readme

zecrey-client-core

Zecrey Client Core Modules

L1 NFT

App.js

import { MoralisProvider } from "@zecrey/zecrey-client-core";

const AppWithProvider = () => {
  return (
    <MoralisProvider>
      <App />
    </MoralisProvider>
  );
};

export default AppWithProvider;

get NFT assets

import { useNFTBalance } from "@zecrey/zecrey-client-core";

const MOCK_NFT_OWNER_ADDRESS = "0x583bb5640b6f363e158a6ddcf5b279dd2938d6d6";

function NFTBalance() {
  const { getNFTBalance, setNFTBalance, NFTBalance, fetchSuccess, isLoading } =
    useNFTBalance(MOCK_NFT_OWNER_ADDRESS);
  useEffect(() => {
    getNFTBalance();
  }, [getNFTBalance]);
}

Legend Basic Information

1. Legend contract

import { getLegendBasicInfo } from "@zecrey/zecrey-client-core";

let contracts = (await getLegendBasicInfo()).contract_addresses; // ['0x0A20FCcD1D6259FEa2a006b1446fc6804ad1FD0d']

2. FT tokens

import { getLegendAssetInfo } from "@zecrey/zecrey-client-core";

let FTs = await getLegendAssetInfo();
// [
//   {
//     asset_id: 0,
//     asset_name: "BNB",
//     asset_decimals: 18,
//     asset_symbol: "BNB",
//     asset_address: "",
//     is_gas_asset:1
//   },
//   {
//     asset_id: 1,
//     asset_name: "LEG",
//     asset_decimals: 18,
//     asset_symbol: "LEG",
//     asset_address: "0x169FBeAC030C23854b66b09245371a540C9C8F89",
//     is_gas_asset:0
//   },
//   {
//     asset_id: 2,
//     asset_name: "REY",
//     asset_decimals: 18,
//     asset_symbol: "REY",
//     asset_address: "0x1375C52ecd487FF88A7017EF2C249d142996E5E9",
//     is_gas_asset:0
//   },
// ]

3. Liquidity tokens

import { getLegendPairBasicInfo } from "@zecrey/zecrey-client-core";

// all the information of all the liquidity tokens
let LPs = await getLegendPairBasicInfo();
// [
//   {
//     pair_index: 0,
//     asset_a_id: 0,
//     asset_a_name: "BNB",
//     asset_a_amount: "199900000000000",
//     asset_b_id: 2,
//     asset_b_name: "REY",
//     asset_b_amount: "50000050100201",
//     fee_Rate: 30,
//     treasury_rate: 5,
//   },
// ]

// liquidity token's asset information by index
let pair = await getLegendPairInfo(0);
// {
//   asset_a_id: 0,
//   asset_a_amount: "0",
//   asset_b_id: 1,
//   asset_b_amount: "0",
//   total_lp_amount: "0",
//   assetA_per_assetB: "0",
//   assetB_per_assetA: "0",
// }

4. Transaction types

import {
  LEGEND_TRANSACTION_TYPE_MAP,
  LEGEND_TRANSACTION_TYPE_NAME_MAP,
} from "@zecrey/zecrey-client-core";

let tx_type = LEGEND_TRANSACTION_TYPE_MAP.TRANSFER; // 6
let tx_type_name = LEGEND_TRANSACTION_TYPE_NAME_MAP.TRANSFER; // "Transfer"

Create Legend Account from Ethereum Private Key

1. Create legend keypair

import { generateLegendSeedFromSK } from "@zecrey/zecrey-client-core";

let sk = "0x1bcb0ae8c17945acfaf9ea546c0b754a599fddf27425bac7e532590324137a7d"; // ethereum private key
let seed = await generateLegendSeedFromSK(sk); // ee823a72698fd05c70fbdf36ba2ea467d33cf628c94ef030383efcb39581e43f
let publicKey = global.getEddsaCompressedPublicKey(seed); // d56fe442700abfb04ed815c1d506af9a45e0ad02680e554787cc7bdf7530b227
let uncompressedPK = global.getEddsaPublicKey(seed); //0c3f61c6e7f9b215b0ecdb1091fe9063d74e6e59e2928a5f731e751ff816071a27b23075df7bcc8747550e6802ade0459aaf06d5c115d84eb0bf0a7042e46fd5

2. Register legend account

import {
  getPointsOfPK,
  registerLegendWithoutSK,
  getRegisterPrice,
  populateRegister,
  estimateRegister,
} from "@zecrey/zecrey-client-core";

let address = "0x09E45d6FcF322c4D93E6aFE7076601FF10BA942E";
let seed = "ee823a72698fd05c70fbdf36ba2ea467d33cf628c94ef030383efcb39581e43f";

// Legend uncompressed public key.
let uncompressed = global.getEddsaPublicKey(seed);
// Get the X and Y points of the public key.
let { x, y } = getPointsOfPK(uncompressed);
// Name to register
let name = "example"; // 3 ~ 32 characters.
// Get price
let price = await getRegisterPrice(provider, OracleContractAddress, name); // "0xb1a2bc2ec50000"
// Regisiter
let contractAddress = (await getLegendBasicInfo()).contract_addresses[0]; // Legend register contract address.
let args = [name, address, x, y, price, contractAddress];
let tx = await registerLegendWithoutSK(...args);
// OR
let args = [name, address, x, y, price, provider, contractAddress];
let data = await populateRegister(...args);
let gasLimit = await estimateRegister(...args);

Get Account Information

import {
  getLegendAccountInfoByName,
  getLegendAccountInfoByPK,
  getLegendTxsByAccountIndex,
} from "@zecrey/zecrey-client-core";

// Get payee's information. Used in asset-transfer.
// Note: throw error if payee doesn't exist yet.
let payee = await getLegendAccountInfoByName("example.legend");
// {
//   account_index: 10,
//   account_pk: '58130e24cd20d9de8a110a20751f0a9b36089400ac0f20ca1993c28ee663318a',
//   assets: [...]
// }

// Get account information. Used in creating or importing accounts.
let legendAccount = await getLegendAccountInfoByPK(publicKey);
// {
//   account_status: 1,
//   account_index: 10,
//   account_name: 'example.legend',
//   assets: [...]
// }

// Get transaction records.
let { txs, total } = await getLegendTxsByAccountIndex(4, offset, limit);
// {
//   total: 1,
//   txs: [
//     {
//       tx_hash: "e9539410-f29b-11ec-b020-fad2edca5836",
//       tx_type: 4,
//       tx_amount: "200000000000000000",
//       tx_info:
//         '{"TxType":4,"AccountIndex":4,"AccountNameHash":"6EDtOQDJgb6eMrcNY2kn2RAopw4d9yW/LrRj2x//RWw=","AssetId":0,"AssetAmount":200000000000000000}',
//       tx_details: [],
//       tx_status: 1,
//       gas_fee_asset_id: 0,
//       gas_fee: "0",
//       nft_index: -1,
//       pair_index: -1,
//       asset_id: 0,
//       native_adress: "0x805e286D05388911cCdB10E3c7b9713415607c72",
//       extra_info: "",
//       memo: "",
//       account_index: 4,
//       nonce: 0,
//       expire_at: 0,
//       status: 0,
//       block_id: 18,
//       block_height: 17,
//       created_at: 1655951208,
//       state_root:
//         "217c4d05cb7e95cffe8dd13651a6eeb7fe6d5255f9f030eefd54d1a73b956b3e",
//     },
//   ],
// },

Get Account Balances

import { getLegendAccountBalances } from "@zecrey/zecrey-client-core";

// both FT tokens and LP tokens
let { ft, lp } = await getLegendAccountBalances(publicKey);

Deposit FT Token

import {
  getLegendBasicInfo,
  populateDepositBNB,
  estimateDepositBNB,
  estimateApproveBEP20,
  populateApproveBEP20,
  populateDepositBEP20,
  estimateDepositBEP20,
} from "@zecrey/zecrey-client-core";

let contractAddress = (await getLegendBasicInfo()).contract_addresses[0]; // Legend contract address.

// Deposit BNB
let args = [
  "example", // legend account name, without '.legend' suffix
  "0.1", // means 0.1 BNB token to deposit
  provider, // Web3Provider or JsonRpcProvider
  contractAddress, // Legend contract address.
];
let data = await populateDepositBNB(...args);
let gasLimit = (await estimateDepositBNB(...args)).toString();

// Approve BEP20
let args = [
  "0x169FBeAC030C23854b66b09245371a540C9C8F89", // token contrac address
  provider, // Web3Provider or JsonRpcProvider
  contractAddress, // Legend contract address.
];
let data = await populateApproveBEP20(...args);
let gasLimit = (await estimateApproveBEP20(...args)).toString();

// Deposit BEP20
let args = [
  "0x169FBeAC030C23854b66b09245371a540C9C8F89", // token contrac address
  "example", // legend account name, without '.legend' suffix
  "0.1", // means 0.1 BEP20 token to deposit
  provider, // Web3Provider or JsonRpcProvider
  contractAddress, // Legend contract address.
];
let data = await populateDepositBEP20(...args);
let gasLimit = (await estimateDepositBEP20(...args)).toString();

Transaction

1. Amounts in transaction

// Note: every amount value used to generating proof has to be cleaned.
let amount = global.cleanPackedAmount(origin_amount);

2. Nonce

import { getLegendNonce } from "@zecrey/zecrey-client-core";

let nonce = await getLegendNonce(account_index);

3. Gas account

import { getLegendAccountInfoByName } from "@zecrey/zecrey-client-core";

let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

4. Gas fee

import {
  getLegendGasFee,
  getLegendWithdrawGasFee,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

let assetId = 0;
let txType = LEGEND_TRANSACTION_TYPE_MAP.TRANSFER;

let gasFee = await getLegendGasFee(assetId, txType); // 49811194312661, without decimals
let withdrawGasFee = await getLegendWithdrawGasFee(assetId); // 49823139288756, without decimals

5. Transfer

import {
  getLegendAccountInfoByName,
  getLegendGasFee
  getLegendNonce,
  sendLegendTx,
  LEGEND_TRANSACTION_TYPE_MAP
} from "@zecrey/zecrey-client-core";

// Note: payee has to exist.
let payee = await getLegendAccountInfoByName("example.legend");
let payee_hash = global.getAccountNameHash("example.legend");

// amount
let amount = global.cleanPackedAmount(utils.parseEther("0.0001").toString());

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(0, LEGEND_TRANSACTION_TYPE_MAP.TRANSFER);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  from_account_index: sender_account_index,
  to_account_index: payee.account_index,
  to_account_name: payee_hash,
  asset_id: 0,
  asset_amount: amount,
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  memo: "",
  call_data: "",
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};
let proof = global.signTransfer(sender_seed, JSON.stringify(args));

let txId = await sendLegendTx(LEGEND_TRANSACTION_TYPE_MAP.TRANSFER, proof);

6. Withdraw

import {
  getLegendAccountInfoByName
  getLegendWithdrawGasFee,
  getLegendNonce,
  sendLegendTx,
  LEGEND_TRANSACTION_TYPE_MAP
} from "@zecrey/zecrey-client-core";

// amount
let amount = global.cleanPackedAmount(utils.parseEther("0.0001").toString());

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendWithdrawGasFee(0);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  from_account_index: sender_acccout_index,
  asset_id: 0,
  asset_amount: amount,
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  to_address: "0x...",
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};
let proof = global.signWithdraw(sender_seed, JSON.stringify(args));

let txId = await sendLegendTx(LEGEND_TRANSACTION_TYPE_MAP.WITHDRAW, proof);

7. Add Liquidity

import {
  getLegendPairInfo,
  getLegendAccountInfoByName
  getLegendGasFee,
  getLegendNonce,
  sendLegendTx,
  LEGEND_TRANSACTION_TYPE_MAP
} from "@zecrey/zecrey-client-core";

// pair information
let pair = await getLegendPairInfo(PAIR_INDEX)

// amount
let originA = utils.parseEther("0.0001").toString()
let originB = new BigNumber(pair.assetB_per_assetA).times(originA).toString();
let amountA = global.cleanPackedAmount(originA);
let amountB = global.cleanPackedAmount(originB);

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(0, LEGEND_TRANSACTION_TYPE_MAP.ADDLIQUIDITY);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  from_account_index: sender_account_index,
  pair_index: PAIR_INDEX,
  asset_a_id: pair.asset_a_id,
  asset_a_amount: amountA,
  asset_b_id: pair.asset_b_id,
  asset_b_amount: amountB,
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: props.nonce
}
let proof = global.signAddLiquidity(
  sender_seed,
  JSON.stringify(args)
)

let txId = await sendLegendTx(LEGEND_TRANSACTION_TYPE_MAP.ADDLIQUIDITY, proof);

8. Remove Liquidity

import {
  getLegendPairInfo,
  getLegendLpValue,
  getLegendAccountInfoByName,
  getLegendGasFee,
  getLegendNonce,
  sendLegendTx,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

// pair information
let pair = await getLegendPairInfo(PAIR_INDEX);

// remove amount
let lp_amount = utils.parseEther("0.0001").toString();

// LP values
let { asset_a_amount, asset_b_amount } = await getLegendLpValue(
  PAIR_INDEX,
  lp_amount
);

// min
let minA = new BigNumber(asset_a_amount).times(0.995).toFix(0); // slippage: 0.5%
let minB = new BigNumber(asset_b_amount).times(0.995).toFix(0); // slippage: 0.5%

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(
  0,
  LEGEND_TRANSACTION_TYPE_MAP.REMOVELIQUIDITY
);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  from_account_index: sender_account_index,
  pair_index: PAIR_INDEX,
  asset_a_id: pair.asset_a_id,
  asset_a_min_amount: global.cleanPackedAmount(minA),
  asset_a_amount_delta: global.cleanPackedAmount(asset_a_amount),
  asset_b_id: pair.asset_b_id,
  asset_b_min_amount: global.cleanPackedAmount(minB),
  asset_b_amount_delta: global.cleanPackedAmount(asset_b_amount),
  lp_amount: global.cleanPackedAmount(lp_amount),
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};
let proof = global.signRemoveLiquidity(sender_seed, JSON.stringify(args));

let txId = await sendLegendTx(
  LEGEND_TRANSACTION_TYPE_MAP.REMOVELIQUIDITY,
  proof
);

9. Swap

import {
  getLegendPairInfo,
  getLegendSwapAmount,
  getLegendAccountInfoByName,
  getLegendGasFee,
  getLegendNonce,
  sendLegendTx,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

// pair information
let pair = await getLegendPairInfo(PAIR_INDEX);
let swap_from_id = pair.asset_a_id;
let swap_to_id = pair.asset_b_id;

// swap amount
let swap_from_amount = utils.parseEther("1").toString();
let is_from = true;
let swap_to_amount = await getLegendSwapAmount(
  PAIR_INDEX,
  swap_from_id,
  swap_from_amount,
  true
);
let min = new BigNumber(swap_to_amount).times(0.995).toString(); // slippage: 0.5%

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(0, LEGEND_TRANSACTION_TYPE_MAP.SWAP);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  from_account_index: sender_account_index,
  pair_index: PAIR_INDEX,
  asset_a_id: swap_from_id,
  asset_a_amount: global.cleanPackedAmount(swap_from_amount),
  asset_b_id: swap_to_id,
  asset_b_min_amount: global.cleanPackedAmount(min),
  asset_b_amount_delta: global.cleanPackedAmount(swap_to_amount),
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};

let proof = global.signSwap(sender_seed, JSON.stringify(args));

let txId = await sendLegendTx(LEGEND_TRANSACTION_TYPE_MAP.SWAP, proof);

10. Create Collection

import {
  getLegendAccountInfoByName,
  getLegendGasFee,
  getLegendNonce,
  createCollection,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(
  0,
  LEGEND_TRANSACTION_TYPE_MAP.CREATECOLLECTION
);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  account_index: sender_account_index,
  collection_id: 1, // any number works
  name: "collection_name",
  introduction: "collection_introduction_text",
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};

let proof = global.signCreateCollection(sender_seed, JSON.stringify(args));

let logo = "collection/jy5ppidyflwdeehvxp7w";
let banner = "collection/jy5ppidyflwdeehvxp7w";
let shortname = "collection_shortname";
let links = [
  "external_link",
  "twitter_link",
  "instagram_link",
  "discord_link",
  "telegram_link",
];
let percentage = 0;

await createCollection(logo, banner, shortname, links, percentage, proof);

11. Mint NFT

import {
  getLegendAccountInfoByName,
  getLegendGasFee,
  getLegendNonce,
  nftContentHash,
  createNFT,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(0, LEGEND_TRANSACTION_TYPE_MAP.MINTNFT);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let properties = JSON.stringify([{ name: "eye", value: "black" }]);
let levels = JSON.stringify([{ name: "height", value: 10 }]);
let stats = JSON.stringify([{ name: "weight", value: 7 }]);

let nft_content_hash = await nftContentHash({
  account_name: sender_account_name,
  collection_id: 1,
  name: "nft_name",
  properties,
  levels,
  stats,
});

let args = {
  creator_account_index: sender_account_index,
  to_account_index: sender_account_index,
  to_account_name_hash: (global as any).getAccountNameHash(sender_account_name),
  nft_content_hash,
  nft_collection_id: l2_collection_id,
  creator_treasury_rate: 30, // means 0.3%
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};

let proof = global.signMintNft(sender_seed, JSON.stringify(args));

await createNFT({
  name: "nft_name",
  collection_id: 1,
  media: "collection/jy5ppidyflwdeehvxp7w",
  discription: "",
  transaction: proof,
  properties,
  levels,
  stats,
});

12. Transfer NFT

import {
  getLegendAccountInfoByName,
  getLegendGasFee,
  getLegendNonce,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

// Note: payee has to exist.
let payee = await getLegendAccountInfoByName("example.legend");
let payee_hash = global.getAccountNameHash("example.legend");

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(0, LEGEND_TRANSACTION_TYPE_MAP.TRANSFERNFT);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  from_account_index: sender_account_index,
  to_account_index: payee.account_index,
  to_account_name: payee_hash,
  nft_index: 1, // ID of NFT to transfer
  call_data: "",
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 0,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};

let proof = global.signTransferNft(sender_seed, JSON.stringify(args));

13. Withdraw NFT

import {
  getLegendAccountInfoByName,
  getLegendWithdrawNFTGasFee,
  getLegendNonce,
} from "@zecrey/zecrey-client-core";

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendWithdrawNFTGasFee(0);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  account_index: sender_account_index,
  nft_index: number;
  to_address: '0x09E45d6FcF322c4D93E6aFE7076601FF10BA942E',
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 1,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
}

let proof = global.signWithdrawNft(sender_seed, JSON.stringify(args));

14. Make Offer

import { getLegendNextOfferId } from "@zecrey/zecrey-client-core";

let offer_id = await getLegendNextOfferId(sender_account_name);

let args = {
  type: 0,
  offer_id,
  account_index: sender_account_index,
  nft_index: 1,
  asset_id: 0,
  asset_amount: "100000000000", // without decimals
  listed_at: Date.now(),
  expired_at: Date.now() + 10 * 60 * 1000,
  treasury_rate: 30, // todo: from API
};

let proof = global.signOffer(sender_seed, JSON.stringify(args));

15. Cancel Offer

import {
  getLegendAccountInfoByName,
  getLegendGasFee,
  getLegendNonce,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(0, LEGEND_TRANSACTION_TYPE_MAP.CANCELOFFER);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  account_index: sender_account_index,
  offer_id: 1, // ID of offer to cancel
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 1,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
};

let proof = global.signCancelOffer(sender_seed, JSON.stringify(args));

16. Atomic Match

import {
  getLegendAccountInfoByName,
  getLegendGasFee,
  getLegendNonce,
  LEGEND_TRANSACTION_TYPE_MAP,
} from "@zecrey/zecrey-client-core";

// gas account
let gasAccountIndex = (await getLegendAccountInfoByName("gas.legend"))
  .account_index;

// gas fee
let gasFee = await getLegendGasFee(0, LEGEND_TRANSACTION_TYPE_MAP.ATOMICMATCH);

// nonce
let nonce = await getLegendNonce(sender_account_index);

let args = {
  account_index: sender_account_index;
  buy_offer: buy_offer.signature,
  sell_offer: sell_offer.signature,
  gas_account_index: gasAccountIndex,
  gas_fee_asset_id: 1,
  gas_fee_asset_amount: gasFee.toString(),
  expired_at: Date.now() + 10 * 60 * 1000,
  nonce: nonce,
}

let proof = global.signAtomicMatch(sender_seed, JSON.stringify(args));

17. Create Legend-NFT account

import { createAccount } from "@zecrey/zecrey-client-core";

let timestamp = Math.floor(Date.now() / 1000);

let sig = global.eddsaSign(sender_seed, `${timestamp}create_account`);

await createAccount({
  signature: sig,
  timestamp,
  profile_image: "collection/jy5ppidyflwdeehvxp7w",
  banner_image: "collection/jy5ppidyflwdeehvxp7w",
  account_name: sender_account_name,
  bio: "",
  email: "",
  external_link: "",
  twitter_link: "",
  instagram_link: "",
});

Transaction Records

import { getLegendTxByHash } from "@zecrey/zecrey-client-core";

// get transaction information
let tx = await getLegendTxByHash("e9539410-f29b-11ec-b020-fad2edca5836");

// get transaction list from mempool
let txs = await getLegendMempoolTxs(); // {total: 1010, mempool_txs: [...]}

GraphQL Query Strings

1. Get popular collections.

import { getPopularCollections } from "@zecrey/zecrey-client-core";

/**
 * Query string for popular collections.
 * Variables:
 *    offset: Int!
 *    limit: Int!
 * @param {string} keyword - search by collection name
 */

const { data, loading, error, refetch } = useQuery(
  getPopularCollections(keyword),
  {
    variables: { offset: 0, limit: 30 },
  }
);

2. Get NFT properties in the collection.

import { getCollectionProperties } from "@zecrey/zecrey-client-core";

/**
 * Query string for collection properties.
 * Variables:
 *    collection_id: bigint
 */

const { data, loading, error, refetch } = useQuery(getCollectionProperties(), {
  variables: { collection_id: 5 },
});

3. Search NFTs by name.

import {
  getNFTs,
  RECENTLY_CREATED,
  RECENTLY_LISTED,
  RECENTLY_SOLD,
  ENDING_SOON,
  PRICE_TO_HIGH,
  PRICE_TO_LOW,
} from "@zecrey/zecrey-client-core";

/**
 * Query string for NFT.
 * Variables:
 *    offset: Int!
 *    limit: Int!
 *    now: bigint
 * @param {string | undefined} keyword - filter by NFT name
 * @param {string | number | undefined} collectionId - filter by collection id
 * @param {boolean | undefined} buyNow - filter by whether any sell-offer attached
 * @param {boolean | undefined} verified - filter by whether the collection verifed
 * @param {{ key: string; value: string }[] | undefined} properties - filter by properties
 * @param {number | undefined} minPrice - filter by min price
 * @param {number | undefined} maxPrice - filter by max price
 * @param {string | undefined} order_by - recently listed | recently created | recently sold | ending soon | price from low to high | price from high to low
 */

const now = useMemo(() => Date.now(), []);
const { data, loading, error, refetch } = useQuery(
  getNFTs(
    keyword,
    collection ? collection.id : undefined,
    buyNow,
    verified,
    properties as any,
    min,
    max || undefined,
    sort_by
  ),
  {
    variables: { offset: 0, limit: 30, now },
  }
);

4. Search collections by name.

import { getSearchCollection } from "@zecrey/zecrey-client-core";

/**
 * Query string for search collections by name.
 * Variables:
 *    keyword: String!
 *    offset: Int!
 *    limit: Int!
 * @param {boolean} verified - filter by whether the collection verifed
 */

const { data, loading, error, refetch } = useQuery(
  getSearchCollection(verified),
  {
    variables: { keyword: "example", offset: 0, limit: 20 },
  }
);

5. Get NFT properties in the collection.

import { getSearchUser } from "@zecrey/zecrey-client-core";

/**
 * Query string for search users by name.
 * Variables:
 *    keyword: String!
 *    offset: Int!
 *    limit: Int!
 */

const { data, loading, error, refetch } = useQuery(getSearchUser(), {
  variables: { keyword: "example", offset: 0, limit: 20 },
});