UNPKG

@tatumio/tatum-v1

Version:

Tatum API client allows browsers and Node.js clients to interact with Tatum API.

665 lines 121 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendOneTransferMultiTokenSignedTransaction = exports.sendOneBurnMultiTokenBatchSignedTransaction = exports.sendOneBurnMultiTokenSignedTransaction = exports.sendOneDeploy721SignedTransaction = exports.sendOneUpdateCashbackForAuthor721SignedTransaction = exports.sendOneTransfer721SignedTransaction = exports.sendOneBurn721SignedTransaction = exports.sendOneMintMultiple721SignedTransaction = exports.sendOneMintMultipleCashback721SignedTransaction = exports.sendOneMintCashback721SignedTransaction = exports.sendOneMintMultiple721ProvenanceSignedTransaction = exports.sendOneMint721ProvenanceSignedTransaction = exports.sendOneMint721SignedTransaction = exports.sendOneDeploy20SignedTransaction = exports.sendOneTransfer20SignedTransaction = exports.sendOneBurn20SignedTransaction = exports.sendOneMint20SignedTransaction = exports.sendOneStoreDataTransaction = exports.sendOneSmartContractReadMethodInvocationTransaction = exports.prepareOneSmartContractWriteMethodInvocation = exports.prepareOneDeployMultiTokenSignedTransaction = exports.prepareOneMintMultiTokenBatchSignedTransaction = exports.prepareOneMintMultiTokenSignedTransaction = exports.prepareOneBatchTransferMultiTokenSignedTransaction = exports.prepareOneTransferMultiTokenSignedTransaction = exports.prepareOneBurnMultiTokenBatchSignedTransaction = exports.prepareOneBurnMultiTokenSignedTransaction = exports.prepareOneDeploy721SignedTransaction = exports.prepareOneUpdateCashbackForAuthor721SignedTransaction = exports.prepareOneTransfer721SignedTransaction = exports.prepareOneBurn721SignedTransaction = exports.prepareOneMintMultiple721SignedTransaction = exports.prepareOneMintMultipleCashback721SignedTransaction = exports.prepareOneMintCashback721SignedTransaction = exports.prepareOneMintMultiple721ProvenanceSignedTransaction = exports.prepareOneMint721ProvenanceSignedTransaction = exports.prepareOneMint721SignedTransaction = exports.prepareOneDeploy20SignedTransaction = exports.prepareOneDeployAuctionSignedTransaction = exports.prepareOneDeployMarketplaceListingSignedTransaction = exports.prepareOneGenerateCustodialWalletSignedTransaction = exports.getOne20ContractDecimals = exports.prepareOneTransfer20SignedTransaction = exports.prepareOneBurn20SignedTransaction = exports.prepareOneMint20SignedTransaction = exports.prepareOneStoreDataTransaction = exports.prepareOneSignedTransaction = exports.signOneKMSTransaction = exports.prepareOneClient = exports.sendOneTransaction = void 0; exports.sendOneSmartContractMethodInvocationTransaction = exports.sendOneDeployMarketplaceListingSignedTransaction = exports.sendOneGenerateCustodialWalletSignedTransaction = exports.sendOneDeployMultiTokenSignedTransaction = exports.sendOneMintMultiTokenBatchSignedTransaction = exports.sendOneMintMultiTokenSignedTransaction = exports.sendOneBatchTransferMultiTokenSignedTransaction = void 0; const crypto_1 = require("@harmony-js/crypto"); const bignumber_js_1 = require("bignumber.js"); const web3_1 = __importDefault(require("web3")); const web3_utils_1 = require("web3-utils"); const blockchain_1 = require("../blockchain"); const tatum_1 = require("../connector/tatum"); const constants_1 = require("../constants"); const erc1155_abi_1 = __importDefault(require("../contracts/erc1155/erc1155_abi")); const erc1155_bytecode_1 = __importDefault(require("../contracts/erc1155/erc1155_bytecode")); const token_abi_1 = __importDefault(require("../contracts/erc20/token_abi")); const token_abi_2 = __importDefault(require("../contracts/erc20/token_abi")); const token_bytecode_1 = __importDefault(require("../contracts/erc20/token_bytecode")); const erc721_abi_1 = __importDefault(require("../contracts/erc721Cashback/erc721_abi")); const erc721_bytecode_1 = __importDefault(require("../contracts/erc721Cashback/erc721_bytecode")); const erc721Provenance_abi_1 = __importDefault(require("../contracts/erc721Provenance/erc721Provenance_abi")); const erc721Provenance_bytecode_1 = __importDefault(require("../contracts/erc721Provenance/erc721Provenance_bytecode")); const marketplace_1 = require("../contracts/marketplace"); const model_1 = require("../model"); const nft_1 = require("../nft"); const wallet_1 = require("../wallet"); const erc721_abi_2 = __importDefault(require("../contracts/erc721General/erc721_abi")); const erc721_bytecode_2 = __importDefault(require("../contracts/erc721General/erc721_bytecode")); const prepareGeneralTx = async (client, testnet, fromPrivateKey, signatureId, to, amount, nonce, data, gasLimit, gasPrice) => { const recipient = (to === null || to === void 0 ? void 0 : to.includes('one')) ? new crypto_1.HarmonyAddress(to).basicHex : to; const tx = { from: 0, to: recipient, value: amount ? `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(amount, 'ether')).toString(16)}` : undefined, data, gas: gasLimit, nonce, gasPrice: gasPrice ? `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(gasPrice, 'gwei')).toString(16)}` : await client.eth.getGasPrice(), }; if (signatureId) { return JSON.stringify(tx); } // we call it to verify that tx will succeed or fail const estimatedGas = await client.eth.estimateGas({ to: recipient, data: data || '', value: tx.value }); tx.gas = gasLimit || estimatedGas; return (await client.eth.accounts.signTransaction(tx, fromPrivateKey)).rawTransaction; }; /** * Send Harmony transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendOneTransaction = async (testnet, body, provider) => { return blockchain_1.oneBroadcast(await exports.prepareOneSignedTransaction(testnet, body, provider)); }; exports.sendOneTransaction = sendOneTransaction; const prepareOneClient = (testnet, provider, fromPrivateKey) => { const client = new web3_1.default(provider || `${process.env.TATUM_API_URL || constants_1.TATUM_API_URL}/v3/one/web3/${process.env.TATUM_API_KEY}`); if (fromPrivateKey) { client.eth.accounts.wallet.clear(); client.eth.accounts.wallet.add(fromPrivateKey); client.eth.defaultAccount = client.eth.accounts.wallet[0].address; } return client; }; exports.prepareOneClient = prepareOneClient; /** * Sign Harmony pending transaction from Tatum KMS * @param tx pending transaction from KMS * @param fromPrivateKey private key to sign transaction with. * @param testnet mainnet or testnet version * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const signOneKMSTransaction = async (tx, fromPrivateKey, testnet, provider) => { if (tx.chain !== model_1.Currency.ONE) { throw Error('Unsupported chain.'); } const client = exports.prepareOneClient(testnet, provider, fromPrivateKey); const transactionConfig = JSON.parse(tx.serializedTransaction); if (!transactionConfig.gas) { transactionConfig.gas = await client.eth.estimateGas({ to: transactionConfig.to, data: transactionConfig.data }); } if (!transactionConfig.gasPrice || transactionConfig.gasPrice === '0' || transactionConfig.gasPrice === 0 || transactionConfig.gasPrice === '0x0') { transactionConfig.gasPrice = await client.eth.getGasPrice(); } return (await client.eth.accounts.signTransaction(transactionConfig, fromPrivateKey)).rawTransaction; }; exports.signOneKMSTransaction = signOneKMSTransaction; /** * Sign Harmony transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneTransfer); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.to, body.amount, body.nonce, undefined, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneSignedTransaction = prepareOneSignedTransaction; /** * Sign Harmony store data transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneStoreDataTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.CreateRecord); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const hexData = client.utils.isHex(body.data) ? client.utils.stringToHex(body.data) : client.utils.toHex(body.data); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, body.to || client.eth.accounts.wallet[0].address, undefined, body.nonce, hexData, (_a = body.ethFee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.ethFee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneStoreDataTransaction = prepareOneStoreDataTransaction; /** * Sign Harmony mint erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMint20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneMint20); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex.trim()); const digits = new bignumber_js_1.BigNumber(10).pow(await contract.methods.decimals().call()); const data = contract.methods .mint(new crypto_1.HarmonyAddress(body.to).basicHex, `0x${new bignumber_js_1.BigNumber(body.amount).multipliedBy(digits).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneMint20SignedTransaction = prepareOneMint20SignedTransaction; /** * Sign Harmony burn erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneBurn20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneBurn20); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex.trim()); const digits = new bignumber_js_1.BigNumber(10).pow(await contract.methods.decimals().call()); const data = contract.methods .burn(`0x${new bignumber_js_1.BigNumber(body.amount).multipliedBy(digits).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneBurn20SignedTransaction = prepareOneBurn20SignedTransaction; /** * Sign Harmony transfer erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneTransfer20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneTransfer20); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const decimals = new bignumber_js_1.BigNumber(10).pow(body.digits); // @ts-ignore const data = new client.eth.Contract(token_abi_2.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex.trim()).methods .transfer(new crypto_1.HarmonyAddress(body.to).basicHex, `0x${new bignumber_js_1.BigNumber(body.amount).multipliedBy(decimals).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneTransfer20SignedTransaction = prepareOneTransfer20SignedTransaction; const getOne20ContractDecimals = async (testnet, contractAddress, provider) => { if (!contractAddress) { throw new Error('Contract address not set.'); } const client = await exports.prepareOneClient(testnet, provider); // @ts-ignore const contract = new client.eth.Contract(token_abi_1.default, contractAddress.trim()); return await contract.methods.decimals().call(); }; exports.getOne20ContractDecimals = getOne20ContractDecimals; /** * Sign Harmony generate custodial wallet transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneGenerateCustodialWalletSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.GenerateCustodialAddress); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const { abi, code } = wallet_1.obtainCustodialAddressType(body); // @ts-ignore const contract = new client.eth.Contract(abi); const data = contract.deploy({ data: code, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneGenerateCustodialWalletSignedTransaction = prepareOneGenerateCustodialWalletSignedTransaction; /** * Sign ONE generate custodial wallet address transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet * @param body content of the transaction to broadcast * @param provider url of the One Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain, or signatureId in case of Tatum KMS */ const prepareOneDeployMarketplaceListingSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.DeployMarketplaceListing); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore // const contract = new client.eth.Contract(auction.abi); const contract = new client.eth.Contract(marketplace_1.listing.abi); const data = contract.deploy({ data: marketplace_1.listing.data, arguments: [body.marketplaceFee, body.feeRecipient], }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneDeployMarketplaceListingSignedTransaction = prepareOneDeployMarketplaceListingSignedTransaction; /** * Sign ONE deploy NFT Auction contract transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet * @param body content of the transaction to broadcast * @param provider url of the One Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain, or signatureId in case of Tatum KMS */ const prepareOneDeployAuctionSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.DeployNftAuction); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(marketplace_1.auction.abi); const data = contract.deploy({ data: marketplace_1.auction.data, arguments: [body.auctionFee, body.feeRecipient], }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneDeployAuctionSignedTransaction = prepareOneDeployAuctionSignedTransaction; /** * Sign Harmony deploy erc20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneDeploy20SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneDeploy20); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default); const data = contract.deploy({ data: token_bytecode_1.default, arguments: [ body.name, body.symbol, new crypto_1.HarmonyAddress(body.address).basicHex, body.digits, `0x${new bignumber_js_1.BigNumber(body.totalCap || body.supply).multipliedBy(new bignumber_js_1.BigNumber(10).pow(body.digits)).toString(16)}`, `0x${new bignumber_js_1.BigNumber(body.supply).multipliedBy(new bignumber_js_1.BigNumber(10).pow(body.digits)).toString(16)}`, ], }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneDeploy20SignedTransaction = prepareOneDeploy20SignedTransaction; /** * Sign Harmony mint erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMint721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneMint721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintWithTokenURI(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, body.url).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } throw new Error('Contract address should not be empty!'); }; exports.prepareOneMint721SignedTransaction = prepareOneMint721SignedTransaction; /** * Sign Harmony mint cashback erc721 provenance transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMint721ProvenanceSignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d; await tatum_1.validateBody(body, model_1.OneMint721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const cb = []; const fv = []; const authors = []; if (body.cashbackValues && body.fixedValues && body.authorAddresses) { body.cashbackValues.map(c => cb.push(`0x${new bignumber_js_1.BigNumber(c).multipliedBy(100).toString(16)}`)); body.fixedValues.map(c => fv.push(`0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`)); body.authorAddresses.map(a => authors.push(new crypto_1.HarmonyAddress(a).basicHex)); } if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintWithTokenURI(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, body.url, authors, cb, fv, body.erc20).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } throw new Error('Contract address should not be empty!'); } else { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintWithTokenURI(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, body.url, authors, cb, fv).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasLimit, (_d = body.fee) === null || _d === void 0 ? void 0 : _d.gasPrice); } throw new Error('Contract address should not be empty!'); } }; exports.prepareOneMint721ProvenanceSignedTransaction = prepareOneMint721ProvenanceSignedTransaction; /** * Sign Harmony mint multiple cashback erc721 provenance transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMintMultiple721ProvenanceSignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d; await tatum_1.validateBody(body, model_1.OneMintMultiple721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const cb = []; const fv = []; if (body.authorAddresses && body.cashbackValues && body.fixedValues) { for (let i = 0; i < body.cashbackValues.length; i++) { const cb2 = []; const fv2 = []; for (let j = 0; j < body.cashbackValues[i].length; j++) { cb2.push(`0x${new bignumber_js_1.BigNumber(body.cashbackValues[i][j]).multipliedBy(100).toString(16)}`); fv2.push(`0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(body.fixedValues[i][j], 'ether')).toString(16)}`); } cb.push(cb2); fv.push(fv2); } } if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintMultiple(body.to.map(t => new crypto_1.HarmonyAddress(t).basicHex), body.tokenId, body.url, body.authorAddresses ? body.authorAddresses.map(a => a.map(a1 => new crypto_1.HarmonyAddress(a1).basicHex)) : [], cb, fv, body.erc20).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); } else { // @ts-ignore const data = new (client).eth.Contract(erc721Provenance_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintMultiple(body.to.map(t => new crypto_1.HarmonyAddress(t).basicHex), body.tokenId, body.url, body.authorAddresses ? body.authorAddresses.map(a => a.map(a1 => new crypto_1.HarmonyAddress(a1).basicHex)) : [], cb, fv).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasLimit, (_d = body.fee) === null || _d === void 0 ? void 0 : _d.gasPrice); } }; exports.prepareOneMintMultiple721ProvenanceSignedTransaction = prepareOneMintMultiple721ProvenanceSignedTransaction; /** * Sign Harmony mint cashback erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMintCashback721SignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d, _e, _f; await tatum_1.validateBody(body, model_1.OneMint721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const cashbacks = body.cashbackValues; const cb = cashbacks.map(c => `0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`); if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintWithCashback(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, body.url, (_a = body.authorAddresses) === null || _a === void 0 ? void 0 : _a.map(a => new crypto_1.HarmonyAddress(a).basicHex), cb, body.erc20).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasLimit, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasPrice); } throw new Error('Contract address should not be empty!'); } else { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintWithCashback(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, body.url, (_d = body.authorAddresses) === null || _d === void 0 ? void 0 : _d.map(a => new crypto_1.HarmonyAddress(a).basicHex), cb).encodeABI(); if (body.contractAddress) { return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_e = body.fee) === null || _e === void 0 ? void 0 : _e.gasLimit, (_f = body.fee) === null || _f === void 0 ? void 0 : _f.gasPrice); } throw new Error('Contract address should not be empty!'); } }; exports.prepareOneMintCashback721SignedTransaction = prepareOneMintCashback721SignedTransaction; /** * Sign Harmony mint multiple cashback erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMintMultipleCashback721SignedTransaction = async (testnet, body, provider) => { var _a, _b, _c, _d, _e, _f; await tatum_1.validateBody(body, model_1.OneMintMultiple721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const cashbacks = body.cashbackValues; const cb = cashbacks.map(cashback => cashback.map(c => `0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`)); if (body.erc20) { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintMultipleCashback(body.to.map(t => new crypto_1.HarmonyAddress(t).basicHex), body.tokenId, body.url, (_a = body.authorAddresses) === null || _a === void 0 ? void 0 : _a.map(a => a.map(a1 => new crypto_1.HarmonyAddress(a1).basicHex)), cb, body.erc20).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasLimit, (_c = body.fee) === null || _c === void 0 ? void 0 : _c.gasPrice); } else { // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintMultipleCashback(body.to.map(t => new crypto_1.HarmonyAddress(t).basicHex), body.tokenId, body.url, (_d = body.authorAddresses) === null || _d === void 0 ? void 0 : _d.map(a => a.map(a1 => new crypto_1.HarmonyAddress(a1).basicHex)), cb).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_e = body.fee) === null || _e === void 0 ? void 0 : _e.gasLimit, (_f = body.fee) === null || _f === void 0 ? void 0 : _f.gasPrice); } }; exports.prepareOneMintMultipleCashback721SignedTransaction = prepareOneMintMultipleCashback721SignedTransaction; /** * Sign Harmony mint multiple erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMintMultiple721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneMintMultiple721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex) .methods.mintMultiple(body.to.map(t => t.trim()), body.tokenId, body.url).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneMintMultiple721SignedTransaction = prepareOneMintMultiple721SignedTransaction; /** * Sign Harmony burn erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneBurn721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneBurn721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods.burn(body.tokenId).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneBurn721SignedTransaction = prepareOneBurn721SignedTransaction; /** * Sign Harmony transfer erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneTransfer721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneTransfer721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(body.provenance ? erc721Provenance_abi_1.default : erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex); const dataBytes = body.provenance ? Buffer.from(body.provenanceData + '\'\'\'###\'\'\'' + web3_utils_1.toWei(body.tokenPrice, 'ether'), 'utf8') : ''; const data = body.provenance ? contract.methods.safeTransfer(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, `0x${dataBytes.toString('hex')}`).encodeABI() : contract.methods.safeTransfer(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, body.value, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneTransfer721SignedTransaction = prepareOneTransfer721SignedTransaction; /** * Sign Harmony update cashback for author 721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneUpdateCashbackForAuthor721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneUpdateCashback721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc721_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .updateCashbackForAuthor(body.tokenId, `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(body.cashbackValue, 'ether')).toString(16)}`).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneUpdateCashbackForAuthor721SignedTransaction = prepareOneUpdateCashbackForAuthor721SignedTransaction; /** * Sign Harmony deploy erc721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneDeploy721SignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneDeploy721); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); if (body.provenance && body.cashback) { throw new Error('Only one of provenance or cashback must be present and true.'); } let abi = erc721_abi_2.default; let delpoyData = erc721_bytecode_2.default; if (body.provenance) { abi = erc721Provenance_abi_1.default; delpoyData = erc721Provenance_bytecode_1.default; } else if (body.cashback) { abi = erc721_abi_1.default; delpoyData = erc721_bytecode_1.default; } // @ts-ignore const data = new client.eth.Contract(abi).deploy({ arguments: [body.name, body.symbol, body.publicMint ? body.publicMint : false], data: delpoyData, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneDeploy721SignedTransaction = prepareOneDeploy721SignedTransaction; /** * Sign Harmony burn multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneBurnMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneBurnMultiToken); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .burn(new crypto_1.HarmonyAddress(body.account).basicHex, body.tokenId, body.amount).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneBurnMultiTokenSignedTransaction = prepareOneBurnMultiTokenSignedTransaction; /** * Sign Harmony burn multiple tokens batch transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneBurnMultiTokenBatchSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneBurnMultiTokenBatch); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .burnBatch(new crypto_1.HarmonyAddress(body.account).basicHex, body.tokenId, body.amounts).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneBurnMultiTokenBatchSignedTransaction = prepareOneBurnMultiTokenBatchSignedTransaction; /** * Sign Harmony transfer multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneTransferMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneTransferMultiToken); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .safeTransfer(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, `0x${new bignumber_js_1.BigNumber(body.amount).toString(16)}`, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneTransferMultiTokenSignedTransaction = prepareOneTransferMultiTokenSignedTransaction; /** * Sign Harmony batch transfer multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneBatchTransferMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneTransferMultiTokenBatch); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const amts = body.amounts.map(amt => `0x${new bignumber_js_1.BigNumber(amt).toString(16)}`); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .safeBatchTransfer(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId.map(token => token.trim()), amts, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneBatchTransferMultiTokenSignedTransaction = prepareOneBatchTransferMultiTokenSignedTransaction; /** * Sign Harmony mint multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMintMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneMintMultiToken); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mint(new crypto_1.HarmonyAddress(body.to).basicHex, body.tokenId, `0x${new bignumber_js_1.BigNumber(body.amount).toString(16)}`, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneMintMultiTokenSignedTransaction = prepareOneMintMultiTokenSignedTransaction; /** * Sign Harmony mint multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneMintMultiTokenBatchSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneMintMultiTokenBatch); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); const batchAmounts = body.amounts.map(amts => amts.map(amt => `0x${new bignumber_js_1.BigNumber(amt).toString(16)}`)); // @ts-ignore const data = new (client).eth.Contract(erc1155_abi_1.default, new crypto_1.HarmonyAddress(body.contractAddress).basicHex).methods .mintBatch(body.to.map(a => new crypto_1.HarmonyAddress(a).basicHex), body.tokenId, batchAmounts, body.data ? body.data : '0x0').encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, new crypto_1.HarmonyAddress(body.contractAddress).basicHex, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneMintMultiTokenBatchSignedTransaction = prepareOneMintMultiTokenBatchSignedTransaction; /** * Sign Harmony deploy multiple tokens transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneDeployMultiTokenSignedTransaction = async (testnet, body, provider) => { var _a, _b; await tatum_1.validateBody(body, model_1.OneDeployMultiToken); const client = await exports.prepareOneClient(testnet, provider, body.fromPrivateKey); // @ts-ignore const data = new client.eth.Contract(erc1155_abi_1.default).deploy({ arguments: [body.uri, body.publicMint ? body.publicMint : false], data: erc1155_bytecode_1.default, }).encodeABI(); return prepareGeneralTx(client, testnet, body.fromPrivateKey, body.signatureId, undefined, undefined, body.nonce, data, (_a = body.fee) === null || _a === void 0 ? void 0 : _a.gasLimit, (_b = body.fee) === null || _b === void 0 ? void 0 : _b.gasPrice); }; exports.prepareOneDeployMultiTokenSignedTransaction = prepareOneDeployMultiTokenSignedTransaction; /** * Sign Harmony smart contract write method invocation transaction with private keys locally. Nothing is broadcast to the blockchain. * @param testnet mainnet or testnet version * @param body content of the transaction to broadcast * @param provider url of the Harmony Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareOneSmartContractWriteMethodInvocation =