1.0.33 • Published 1 year ago

@zecrey/zecrey-client-core v1.0.33

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

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 },
});
1.0.33

1 year ago

0.3.75

2 years ago

0.3.74

2 years ago

0.3.73

2 years ago

0.3.72

2 years ago

0.3.71

2 years ago

0.3.70

2 years ago

0.3.79

2 years ago

0.3.78

2 years ago

0.3.77

2 years ago

0.3.76

2 years ago

0.3.69

2 years ago

0.3.92

2 years ago

0.3.90

2 years ago

0.3.86

2 years ago

0.3.85

2 years ago

0.3.84

2 years ago

0.3.83

2 years ago

0.3.82

2 years ago

0.3.81

2 years ago

0.3.80

2 years ago

0.3.89

2 years ago

0.3.88

2 years ago

0.3.87

2 years ago

1.0.19

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.32

1 year ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

0.2.27

2 years ago

0.2.26

2 years ago

0.2.25

2 years ago

0.2.24

2 years ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.21

2 years ago

0.2.20

2 years ago

0.2.19

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.3.64

2 years ago

0.2.96

2 years ago

0.3.63

2 years ago

0.2.95

2 years ago

0.3.62

2 years ago

0.2.94

2 years ago

0.3.61

2 years ago

0.2.93

2 years ago

0.3.60

2 years ago

0.2.91

2 years ago

0.2.90

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.3.68

2 years ago

0.2.12

2 years ago

0.3.67

2 years ago

0.2.99

2 years ago

0.2.11

2 years ago

0.3.66

2 years ago

0.2.98

2 years ago

0.2.10

2 years ago

0.3.65

2 years ago

0.2.97

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.53

2 years ago

0.2.85

2 years ago

0.3.52

2 years ago

0.2.84

2 years ago

0.3.51

2 years ago

0.2.83

2 years ago

0.3.50

2 years ago

0.2.82

2 years ago

0.2.81

2 years ago

0.2.80

2 years ago

0.3.59

2 years ago

0.3.58

2 years ago

0.3.57

2 years ago

0.2.89

2 years ago

0.3.56

2 years ago

0.2.88

2 years ago

0.3.55

2 years ago

0.2.87

2 years ago

0.3.54

2 years ago

0.2.86

2 years ago

0.3.42

2 years ago

0.2.74

2 years ago

0.3.41

2 years ago

0.2.73

2 years ago

0.3.40

2 years ago

0.2.72

2 years ago

0.2.71

2 years ago

0.2.70

2 years ago

0.3.49

2 years ago

0.3.48

2 years ago

0.3.47

2 years ago

0.2.79

2 years ago

0.3.46

2 years ago

0.2.78

2 years ago

0.3.45

2 years ago

0.2.77

2 years ago

0.3.44

2 years ago

0.2.76

2 years ago

0.3.43

2 years ago

0.2.75

2 years ago

0.3.31

2 years ago

0.2.63

2 years ago

0.3.30

2 years ago

0.2.62

2 years ago

0.2.61

2 years ago

0.2.60

2 years ago

0.3.39

2 years ago

0.2.100

2 years ago

0.3.38

2 years ago

0.3.37

2 years ago

0.2.69

2 years ago

0.3.36

2 years ago

0.2.68

2 years ago

0.3.35

2 years ago

0.2.67

2 years ago

0.3.34

2 years ago

0.2.66

2 years ago

0.3.33

2 years ago

0.2.65

2 years ago

0.3.32

2 years ago

0.2.64

2 years ago

0.3.29

2 years ago

0.3.20

2 years ago

0.2.52

2 years ago

0.2.51

2 years ago

0.2.50

2 years ago

0.3.28

2 years ago

0.3.27

2 years ago

0.2.59

2 years ago

0.3.26

2 years ago

0.2.58

2 years ago

0.3.25

2 years ago

0.2.57

2 years ago

0.3.24

2 years ago

0.2.56

2 years ago

0.3.23

2 years ago

0.2.55

2 years ago

0.3.22

2 years ago

0.2.54

2 years ago

0.3.21

2 years ago

0.2.53

2 years ago

0.3.19

2 years ago

0.3.18

2 years ago

0.2.41

2 years ago

0.2.40

2 years ago

0.3.9

2 years ago

0.3.17

2 years ago

0.2.49

2 years ago

0.3.16

2 years ago

0.2.48

2 years ago

0.3.15

2 years ago

0.2.47

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.2.45

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.2.43

2 years ago

0.3.10

2 years ago

0.2.42

2 years ago

0.2.39

2 years ago

0.2.30

2 years ago

0.2.38

2 years ago

0.2.37

2 years ago

0.2.36

2 years ago

0.2.35

2 years ago

0.2.34

2 years ago

0.2.33

2 years ago

0.2.32

2 years ago

0.2.31

2 years ago

0.2.29

2 years ago

0.2.28

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.5

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.4

3 years ago

0.1.0

3 years ago