UNPKG

@tatumio/tatum-v1

Version:

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

845 lines 103 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendBscBurnMultiTokenTransaction = exports.sendUpdateCashbackForAuthorBep721Transaction = exports.sendBurnBep721Transaction = exports.sendMintBep721ProvenanceTransaction = exports.sendMintMultipleBep721ProvenanceTransaction = exports.sendMintMultipleBep721Transaction = exports.sendMintMultipleCashbackBep721Transaction = exports.sendMintBepCashback721Transaction = exports.sendBscMintMultiTokenBatchTransaction = exports.sendBscMintMultiTokenTransaction = exports.sendBscDeployMultiTokenTransaction = exports.sendBscGenerateCustodialWalletSignedTransaction = exports.sendMintBep721Transaction = exports.sendBscSmartContractMethodInvocationTransaction = exports.sendDeployBep20Transaction = exports.sendCustomBep20Transaction = exports.sendBscOrBep20Transaction = exports.sendBscStoreDataTransaction = exports.sendBscSmartContractReadMethodInvocationTransaction = exports.prepareBscDeployMultiTokenSignedTransaction = exports.prepareBscMintMultiTokenBatchSignedTransaction = exports.prepareBscMintMultiTokenSignedTransaction = exports.prepareBscBatchTransferMultiTokenSignedTransaction = exports.prepareBscTransferMultiTokenSignedTransaction = exports.prepareBscBurnMultiTokenBatchSignedTransaction = exports.prepareBscBurnMultiTokenSignedTransaction = exports.prepareBscDeployAuctionSignedTransaction = exports.prepareBscDeployMarketplaceListingSignedTransaction = exports.prepareBscDeployBep721SignedTransaction = exports.prepareBscUpdateCashbackForAuthorErc721SignedTransaction = exports.prepareBscTransferBep721SignedTransaction = exports.prepareBscBurnBep721SignedTransaction = exports.prepareBscMintMultipleBep721SignedTransaction = exports.prepareBscMintMultipleCashbackBep721SignedTransaction = exports.prepareBscMintBepCashback721SignedTransaction = exports.prepareBscMintBep721ProvenanceSignedTransaction = exports.prepareBscMintMultipleBep721ProvenanceSignedTransaction = exports.prepareBscMintBep721SignedTransaction = exports.prepareBscSmartContractWriteMethodInvocation = exports.prepareBscGenerateCustodialWalletSignedTransaction = exports.prepareDeployBep20SignedTransaction = exports.prepareCustomBep20SignedTransaction = exports.prepareBscOrBep20SignedTransaction = exports.prepareBurnBep20SignedTransaction = exports.prepareMintBep20SignedTransaction = exports.prepareBscStoreDataTransaction = exports.getBscBep20ContractDecimals = exports.signBscKMSTransaction = exports.getBscClient = exports.bscGetGasPriceInWei = void 0; exports.sendBscDeployMarketplaceListingSignedTransaction = exports.sendDeployBep721Transaction = exports.sendBscMultiTokenBatchTransaction = exports.sendBscMultiTokenTransaction = exports.sendBep721Transaction = exports.sendBscBurnBatchMultiTokenTransaction = void 0; 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 erc721_abi_2 = __importDefault(require("../contracts/erc721General/erc721_abi")); const erc721_bytecode_2 = __importDefault(require("../contracts/erc721General/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"); /** * Estimate Gas price for the transaction. */ const bscGetGasPriceInWei = async () => { return web3_1.default.utils.toWei('10', 'gwei'); }; exports.bscGetGasPriceInWei = bscGetGasPriceInWei; /** * Returns BSC server to connect to. * * @param provider url of the BSC Server to connect to. If not set, default public server will be used. * @param fromPrivateKey optional private key of sender account */ const getBscClient = (provider, fromPrivateKey) => { const client = new web3_1.default(provider || `${process.env.TATUM_API_URL || constants_1.TATUM_API_URL}/v3/bsc/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.getBscClient = getBscClient; const prepareBscSignedTransactionAbstraction = async (client, transaction, signatureId, fromPrivateKey, fee) => { var _a; const gasPrice = fee ? client.utils.toWei(fee.gasPrice, 'gwei') : await exports.bscGetGasPriceInWei(); const tx = Object.assign(Object.assign({}, transaction), { gasPrice, gas: (fee === null || fee === void 0 ? void 0 : fee.gasLimit) || undefined }); if (signatureId) { return JSON.stringify(tx); } const estimatedGas = await client.eth.estimateGas(tx); tx.gas = (_a = fee === null || fee === void 0 ? void 0 : fee.gasLimit) !== null && _a !== void 0 ? _a : estimatedGas; return (await client.eth.accounts.signTransaction(tx, fromPrivateKey)).rawTransaction; }; /** * Sign BSC pending transaction from Tatum KMS * @param tx pending transaction from KMS * @param fromPrivateKey private key to sign transaction with. * @param provider url of the BSC Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const signBscKMSTransaction = async (tx, fromPrivateKey, provider) => { if (tx.chain !== model_1.Currency.BSC) { throw Error('Unsupported chain.'); } const client = exports.getBscClient(provider, fromPrivateKey); const transactionConfig = JSON.parse(tx.serializedTransaction); const gas = await client.eth.estimateGas(transactionConfig); if (!transactionConfig.gas) { transactionConfig.gas = gas; } if (!transactionConfig.nonce) { transactionConfig.nonce = await blockchain_1.bscGetTransactionsCount(client.eth.defaultAccount); } if (!transactionConfig.gasPrice || transactionConfig.gasPrice === '0' || transactionConfig.gasPrice === 0 || transactionConfig.gasPrice === '0x0') { transactionConfig.gasPrice = await exports.bscGetGasPriceInWei(); } return (await client.eth.accounts.signTransaction(transactionConfig, fromPrivateKey)).rawTransaction; }; exports.signBscKMSTransaction = signBscKMSTransaction; const getBscBep20ContractDecimals = async (testnet, contractAddress, provider) => { if (!contractAddress) { throw new Error('Contract address not set.'); } const client = await exports.getBscClient(provider); // @ts-ignore const contract = new client.eth.Contract(token_abi_1.default, contractAddress.trim()); return await contract.methods.decimals().call(); }; exports.getBscBep20ContractDecimals = getBscBep20ContractDecimals; /** * Sign Bsc Store data transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscStoreDataTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.CreateRecord); const { fromPrivateKey, to, ethFee, data, nonce, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); const address = to || client.eth.defaultAccount; if (!address) { throw new Error('Recipient must be provided.'); } const hexData = client.utils.isHex(data) ? client.utils.stringToHex(data) : client.utils.toHex(data); const addressNonce = nonce ? nonce : await blockchain_1.bscGetTransactionsCount(address); const customFee = ethFee ? Object.assign(Object.assign({}, ethFee), { gasPrice: client.utils.toWei(ethFee.gasPrice, 'gwei') }) : { gasLimit: `${hexData.length * 68 + 21000}`, gasPrice: await exports.bscGetGasPriceInWei(), }; const tx = { from: 0, to: address.trim(), value: '0', gasPrice: customFee.gasPrice, gas: customFee.gasLimit, data: hexData, nonce: addressNonce, }; if (signatureId) { return JSON.stringify(tx); } return (await client.eth.accounts.signTransaction(tx, fromPrivateKey)).rawTransaction; }; exports.prepareBscStoreDataTransaction = prepareBscStoreDataTransaction; /** * Sign BEP20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareMintBep20SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.MintErc20); const { fromPrivateKey, amount, to, contractAddress, nonce, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default, contractAddress.trim()); const digits = new bignumber_js_1.BigNumber(10).pow(await contract.methods.decimals().call()); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.mint(to.trim(), `0x${new bignumber_js_1.BigNumber(amount).multipliedBy(digits).toString(16)}`).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey); }; exports.prepareMintBep20SignedTransaction = prepareMintBep20SignedTransaction; /** * Sign BEP20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBurnBep20SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.BurnErc20); const { fromPrivateKey, amount, contractAddress, nonce, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default, contractAddress.trim()); const digits = new bignumber_js_1.BigNumber(10).pow(await contract.methods.decimals().call()); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.burn(`0x${new bignumber_js_1.BigNumber(amount).multipliedBy(digits).toString(16)}`).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey); }; exports.prepareBurnBep20SignedTransaction = prepareBurnBep20SignedTransaction; /** * Sign Bsc or supported BEP20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscOrBep20SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.TransferBscBep20); const { fromPrivateKey, to, amount, currency, fee, data, nonce, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); let tx; if (currency === model_1.Currency.BSC) { tx = { from: 0, to: to.trim(), value: client.utils.toWei(`${amount}`, 'ether'), data: data ? (client.utils.isHex(data) ? client.utils.stringToHex(data) : client.utils.toHex(data)) : undefined, nonce, }; } else { // @ts-ignore const contract = new client.eth.Contract([constants_1.TRANSFER_METHOD_ABI], constants_1.CONTRACT_ADDRESSES[currency]); const digits = new bignumber_js_1.BigNumber(10).pow(constants_1.CONTRACT_DECIMALS[currency]); tx = { from: 0, to: constants_1.CONTRACT_ADDRESSES[currency], data: contract.methods.transfer(to.trim(), `0x${new bignumber_js_1.BigNumber(amount).multipliedBy(digits).toString(16)}`).encodeABI(), nonce, }; } return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscOrBep20SignedTransaction = prepareBscOrBep20SignedTransaction; /** * Sign Bsc custom BEP20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareCustomBep20SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.TransferErc20); const { fromPrivateKey, to, amount, contractAddress, digits, fee, nonce, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract([constants_1.TRANSFER_METHOD_ABI], contractAddress); const decimals = new bignumber_js_1.BigNumber(10).pow(digits); const tx = { from: 0, to: contractAddress, data: contract.methods.transfer(to.trim(), `0x${new bignumber_js_1.BigNumber(amount).multipliedBy(decimals).toString(16)}`).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareCustomBep20SignedTransaction = prepareCustomBep20SignedTransaction; /** * Sign Bsc deploy BEP20 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareDeployBep20SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.DeployErc20); const { name, address, symbol, supply, digits, fromPrivateKey, nonce, fee, signatureId, totalCap, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(token_abi_2.default); const deploy = contract.deploy({ data: token_bytecode_1.default, arguments: [ name, symbol, address, digits, `0x${new bignumber_js_1.BigNumber(totalCap || supply).multipliedBy(new bignumber_js_1.BigNumber(10).pow(digits)).toString(16)}`, `0x${new bignumber_js_1.BigNumber(supply).multipliedBy(new bignumber_js_1.BigNumber(10).pow(digits)).toString(16)}`, ], }); const tx = { from: 0, data: deploy.encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareDeployBep20SignedTransaction = prepareDeployBep20SignedTransaction; /** * Sign Bsc generate custodial wallet address transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscGenerateCustodialWalletSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.GenerateCustodialAddress); const client = exports.getBscClient(provider, body.fromPrivateKey); const { abi, code } = wallet_1.obtainCustodialAddressType(body); // @ts-ignore const contract = new client.eth.Contract(abi); const deploy = contract.deploy({ data: code, }); const tx = { from: 0, data: deploy.encodeABI(), nonce: body.nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, body.signatureId, body.fromPrivateKey, body.fee); }; exports.prepareBscGenerateCustodialWalletSignedTransaction = prepareBscGenerateCustodialWalletSignedTransaction; /** * Sign Bsc invoke smart contract transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscSmartContractWriteMethodInvocation = async (body, provider) => { await tatum_1.validateBody(body, model_1.SmartContractMethodInvocation); const { fromPrivateKey, fee, params, methodName, methodABI, contractAddress, nonce, amount, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); const contract = new client.eth.Contract([methodABI]); const tx = { from: 0, to: contractAddress.trim(), value: amount ? `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(amount, 'ether')).toString(16)}` : undefined, data: contract.methods[methodName](...params).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscSmartContractWriteMethodInvocation = prepareBscSmartContractWriteMethodInvocation; /** * Sign Bsc mint ERC 721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintBep721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthMintErc721); const { fromPrivateKey, to, tokenId, contractAddress, nonce, fee, url, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721_abi_1.default, contractAddress); if (contractAddress) { const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.mintWithTokenURI(to.trim(), tokenId, url).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); } throw new Error('Contract address should not be empty'); }; exports.prepareBscMintBep721SignedTransaction = prepareBscMintBep721SignedTransaction; /** * Sign Bsc mint multiple ERC 721 Cashback transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintMultipleBep721ProvenanceSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthMintMultipleErc721); const { fromPrivateKey, to, tokenId, contractAddress, url, nonce, signatureId, authorAddresses, cashbackValues, fixedValues, erc20, fee, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721Provenance_abi_1.default, contractAddress); const cb = []; const fv = []; if (authorAddresses && cashbackValues && fixedValues) { for (let i = 0; i < cashbackValues.length; i++) { const cb2 = []; const fv2 = []; for (let j = 0; j < cashbackValues[i].length; j++) { cb2.push(`0x${new bignumber_js_1.BigNumber(cashbackValues[i][j]).multipliedBy(100).toString(16)}`); fv2.push(`0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(fixedValues[i][j], 'ether')).toString(16)}`); } cb.push(cb2); fv.push(fv2); } } const tx = { from: 0, to: contractAddress.trim(), data: erc20 ? contract.methods.mintMultiple(to.map(t => t.trim()), tokenId, url, authorAddresses ? authorAddresses : [], cb, fv, erc20).encodeABI() : contract.methods.mintMultiple(to.map(t => t.trim()), tokenId, url, authorAddresses ? authorAddresses : [], cb, fv).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscMintMultipleBep721ProvenanceSignedTransaction = prepareBscMintMultipleBep721ProvenanceSignedTransaction; /** * Sign Bsc mint ERC 721 provenance transaction with cashback via private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintBep721ProvenanceSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthMintErc721); const { fromPrivateKey, to, tokenId, contractAddress, nonce, fee, url, signatureId, authorAddresses, cashbackValues, fixedValues, erc20, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721Provenance_abi_1.default, contractAddress); const cb = []; const fval = []; if (authorAddresses && cashbackValues && fixedValues) { cashbackValues.map(c => cb.push(`0x${new bignumber_js_1.BigNumber(c).multipliedBy(100).toString(16)}`)); fixedValues.map(c => fval.push(`0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`)); } if (contractAddress) { const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.mintWithTokenURI(to.trim(), tokenId, url, authorAddresses ? authorAddresses : [], cb, fval, erc20 ? erc20 : null).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); } throw new Error('Contract address should not be empty!'); }; exports.prepareBscMintBep721ProvenanceSignedTransaction = prepareBscMintBep721ProvenanceSignedTransaction; /** * Sign Bsc mint ERC 721 transaction with cashback via private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintBepCashback721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthMintErc721); const { fromPrivateKey, to, tokenId, contractAddress, nonce, fee, url, signatureId, authorAddresses, cashbackValues, erc20, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721_abi_1.default, contractAddress); const cashbacks = cashbackValues; const cb = cashbacks.map(c => `0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`); if (contractAddress) { const tx = { from: 0, to: contractAddress.trim(), data: erc20 ? contract.methods.mintWithCashback(to.trim(), tokenId, url, authorAddresses, cb, erc20).encodeABI() : contract.methods.mintWithCashback(to.trim(), tokenId, url, authorAddresses, cb).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); } throw new Error('Contract address should not be empty!'); }; exports.prepareBscMintBepCashback721SignedTransaction = prepareBscMintBepCashback721SignedTransaction; /** * Sign Bsc mint multiple ERC 721 Cashback transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintMultipleCashbackBep721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthMintMultipleErc721); const { fromPrivateKey, to, tokenId, contractAddress, url, nonce, signatureId, authorAddresses, cashbackValues, fee, erc20, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721_abi_1.default, contractAddress); const cashbacks = cashbackValues; const cb = cashbacks.map(cashback => cashback.map(c => `0x${new bignumber_js_1.BigNumber(client.utils.toWei(c, 'ether')).toString(16)}`)); const tx = { from: 0, to: contractAddress.trim(), data: erc20 ? contract.methods.mintMultipleCashback(to.map(t => t.trim()), tokenId, url, authorAddresses, cb, erc20).encodeABI() : contract.methods.mintMultipleCashback(to.map(t => t.trim()), tokenId, url, authorAddresses, cb).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscMintMultipleCashbackBep721SignedTransaction = prepareBscMintMultipleCashbackBep721SignedTransaction; /** * Sign Bsc mint multiple ERC 721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintMultipleBep721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthMintMultipleErc721); const { fromPrivateKey, to, tokenId, contractAddress, url, nonce, signatureId, fee, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721_abi_1.default, contractAddress); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.mintMultiple(to.map(t => t.trim()), tokenId, url).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscMintMultipleBep721SignedTransaction = prepareBscMintMultipleBep721SignedTransaction; /** * Sign Bsc burn ERC 721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscBurnBep721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthBurnErc721); const { fromPrivateKey, tokenId, fee, contractAddress, nonce, signatureId, } = body; const client = exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721_abi_1.default, contractAddress); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.burn(tokenId).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscBurnBep721SignedTransaction = prepareBscBurnBep721SignedTransaction; /** * Sign Bsc transfer ERC 721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscTransferBep721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthTransferErc721); const { fromPrivateKey, to, tokenId, fee, contractAddress, nonce, signatureId, value, provenance, provenanceData, tokenPrice, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(provenance ? erc721Provenance_abi_1.default : erc721_abi_1.default, contractAddress); const dataBytes = provenance ? Buffer.from(provenanceData + '\'\'\'###\'\'\'' + web3_utils_1.toWei(tokenPrice, 'ether'), 'utf8') : ''; const tokenData = provenance ? contract.methods.safeTransfer(to.trim(), tokenId, `0x${dataBytes.toString('hex')}`).encodeABI() : contract.methods.safeTransfer(to.trim(), tokenId).encodeABI(); const tx = { from: 0, to: contractAddress.trim(), data: tokenData, nonce, value: value ? `0x${new bignumber_js_1.BigNumber(value).multipliedBy(1e18).toString(16)}` : undefined, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscTransferBep721SignedTransaction = prepareBscTransferBep721SignedTransaction; /** * Sign Bsc update cashback ERC 721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscUpdateCashbackForAuthorErc721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.UpdateCashbackErc721); const { fromPrivateKey, cashbackValue, tokenId, fee, contractAddress, nonce, signatureId, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc721_abi_1.default, contractAddress); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.updateCashbackForAuthor(tokenId, `0x${new bignumber_js_1.BigNumber(web3_utils_1.toWei(cashbackValue, 'ether')).toString(16)}`).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscUpdateCashbackForAuthorErc721SignedTransaction = prepareBscUpdateCashbackForAuthorErc721SignedTransaction; /** * Sign Bsc deploy ERC 721 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscDeployBep721SignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthDeployErc721); const { fromPrivateKey, fee, name, symbol, nonce, signatureId, provenance, cashback, publicMint, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); if (provenance && cashback) { throw new Error('Only one of provenance or cashback must be present and true.'); } let abi = erc721_abi_2.default; let data = erc721_bytecode_2.default; if (provenance) { abi = erc721Provenance_abi_1.default; data = erc721Provenance_bytecode_1.default; } else if (cashback) { abi = erc721_abi_1.default; data = erc721_bytecode_1.default; } // @ts-ignore const contract = new client.eth.Contract(abi, null, { data, }); // @ts-ignore const deploy = contract.deploy({ arguments: [name, symbol, publicMint ? publicMint : false], }); const tx = { from: 0, data: deploy.encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscDeployBep721SignedTransaction = prepareBscDeployBep721SignedTransaction; /** * Sign BSC generate custodial wallet address transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc 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 prepareBscDeployMarketplaceListingSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.DeployMarketplaceListing); return deployContract(marketplace_1.listing.abi, marketplace_1.listing.data, [body.marketplaceFee, body.feeRecipient], body.fromPrivateKey, body.fee, body.nonce, body.signatureId, provider); }; exports.prepareBscDeployMarketplaceListingSignedTransaction = prepareBscDeployMarketplaceListingSignedTransaction; /** * Sign BSC deploy NFT Auction contract transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc 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 prepareBscDeployAuctionSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.DeployNftAuction); return deployContract(marketplace_1.auction.abi, marketplace_1.auction.data, [body.auctionFee, body.feeRecipient], body.fromPrivateKey, body.fee, body.nonce, body.signatureId, provider); }; exports.prepareBscDeployAuctionSignedTransaction = prepareBscDeployAuctionSignedTransaction; const deployContract = async (abi, bytecode, args, fromPrivateKey, fee, nonce, signatureId, provider) => { const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(abi, null, { data: bytecode, }); // @ts-ignore const deploy = contract.deploy({ arguments: args, }); const tx = { from: 0, data: deploy.encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; /** * Sign Bsc burn ERC 1155 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscBurnMultiTokenSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthBurnMultiToken); const { fromPrivateKey, account, tokenId, amount, fee, contractAddress, nonce, signatureId, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc1155_abi_1.default, contractAddress); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.burn(account, tokenId, amount).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscBurnMultiTokenSignedTransaction = prepareBscBurnMultiTokenSignedTransaction; const prepareBscBurnMultiTokenBatchSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthBurnMultiTokenBatch); const { fromPrivateKey, account, tokenId, amounts, fee, contractAddress, nonce, signatureId, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc1155_abi_1.default, contractAddress); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.burnBatch(account, tokenId, amounts).encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscBurnMultiTokenBatchSignedTransaction = prepareBscBurnMultiTokenBatchSignedTransaction; const prepareBscTransferMultiTokenSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.TransferMultiToken); const { fromPrivateKey, to, tokenId, fee, contractAddress, nonce, signatureId, amount, data, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc1155_abi_1.default, contractAddress); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.safeTransfer(to.trim(), tokenId, `0x${new bignumber_js_1.BigNumber(amount).toString(16)}`, data ? data : '0x0').encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscTransferMultiTokenSignedTransaction = prepareBscTransferMultiTokenSignedTransaction; const prepareBscBatchTransferMultiTokenSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.TransferMultiTokenBatch); const { fromPrivateKey, to, tokenId, fee, contractAddress, nonce, signatureId, amounts, data, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc1155_abi_1.default, contractAddress); const amts = amounts.map(amt => `0x${new bignumber_js_1.BigNumber(amt).toString(16)}`); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.safeBatchTransfer(to.trim(), tokenId.map(token => token.trim()), amts, data ? data : '0x0').encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscBatchTransferMultiTokenSignedTransaction = prepareBscBatchTransferMultiTokenSignedTransaction; /** * Sign Bsc mint ERC 1155 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Ethereum Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintMultiTokenSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.MintMultiToken); const { fromPrivateKey, to, tokenId, contractAddress, nonce, data, fee, amount, signatureId, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc1155_abi_1.default, contractAddress); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.mint(to.trim(), tokenId, `0x${new bignumber_js_1.BigNumber(amount).toString(16)}`, data ? data : '0x0').encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscMintMultiTokenSignedTransaction = prepareBscMintMultiTokenSignedTransaction; /** * Sign BSC mint ERC 1155 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Ethereum Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscMintMultiTokenBatchSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.MintMultiTokenBatch); const { fromPrivateKey, to, tokenId, contractAddress, nonce, data, fee, amounts, signatureId, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new (client).eth.Contract(erc1155_abi_1.default, contractAddress); const amts = amounts.map(amts => amts.map(amt => `0x${new bignumber_js_1.BigNumber(amt).toString(16)}`)); const tx = { from: 0, to: contractAddress.trim(), data: contract.methods.mintBatch(to, tokenId, amts, data ? data : '0x0').encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscMintMultiTokenBatchSignedTransaction = prepareBscMintMultiTokenBatchSignedTransaction; /** * Sign Bsc deploy ERC 1155 transaction with private keys locally. Nothing is broadcast to the blockchain. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction data to be broadcast to blockchain. */ const prepareBscDeployMultiTokenSignedTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.EthDeployMultiToken); const { fromPrivateKey, fee, uri, nonce, signatureId, publicMint, } = body; const client = await exports.getBscClient(provider, fromPrivateKey); // @ts-ignore const contract = new client.eth.Contract(erc1155_abi_1.default, null, { data: erc1155_bytecode_1.default, }); // @ts-ignore const deploy = contract.deploy({ arguments: [uri, publicMint ? publicMint : false], }); const tx = { from: 0, data: deploy.encodeABI(), nonce, }; return await prepareBscSignedTransactionAbstraction(client, tx, signatureId, fromPrivateKey, fee); }; exports.prepareBscDeployMultiTokenSignedTransaction = prepareBscDeployMultiTokenSignedTransaction; /** * Send Bsc invoke smart contract transaction to the blockchain. * Invoked method only reads from blockchain the data and returns them back. * * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. */ const sendBscSmartContractReadMethodInvocationTransaction = async (body, provider) => { await tatum_1.validateBody(body, model_1.SmartContractReadMethodInvocation); const { params, methodName, methodABI, contractAddress, } = body; const client = exports.getBscClient(provider); const contract = new client.eth.Contract([methodABI], contractAddress); return { data: await contract.methods[methodName](...params).call() }; }; exports.sendBscSmartContractReadMethodInvocationTransaction = sendBscSmartContractReadMethodInvocationTransaction; /** * Send Bsc store data transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendBscStoreDataTransaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareBscStoreDataTransaction(body, provider), body.signatureId); exports.sendBscStoreDataTransaction = sendBscStoreDataTransaction; /** * Send Bsc or supported BEP20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendBscOrBep20Transaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareBscOrBep20SignedTransaction(body, provider), body.signatureId); exports.sendBscOrBep20Transaction = sendBscOrBep20Transaction; /** * Send Bsc custom BEP20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendCustomBep20Transaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareCustomBep20SignedTransaction(body, provider), body.signatureId); exports.sendCustomBep20Transaction = sendCustomBep20Transaction; /** * Send Bsc deploy BEP20 transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendDeployBep20Transaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareDeployBep20SignedTransaction(body, provider), body.signatureId); exports.sendDeployBep20Transaction = sendDeployBep20Transaction; /** * Send Bsc invoke smart contract transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendBscSmartContractMethodInvocationTransaction = async (body, provider) => { if (body.methodABI.stateMutability === 'view') { return exports.sendBscSmartContractReadMethodInvocationTransaction(body, provider); } return blockchain_1.bscBroadcast(await exports.prepareBscSmartContractWriteMethodInvocation(body, provider), body.signatureId); }; exports.sendBscSmartContractMethodInvocationTransaction = sendBscSmartContractMethodInvocationTransaction; /** * Send Bsc BEP721 mint transaction to the blockchain. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendMintBep721Transaction = async (body, provider) => { if (!body.fromPrivateKey && !body.fromPrivateKey) { return nft_1.mintNFT(body); } return blockchain_1.bscBroadcast(await exports.prepareBscMintBep721SignedTransaction(body, provider), body.signatureId); }; exports.sendMintBep721Transaction = sendMintBep721Transaction; const sendBscGenerateCustodialWalletSignedTransaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareBscGenerateCustodialWalletSignedTransaction(body, provider), body.signatureId); exports.sendBscGenerateCustodialWalletSignedTransaction = sendBscGenerateCustodialWalletSignedTransaction; // MultiToken const sendBscDeployMultiTokenTransaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareBscDeployMultiTokenSignedTransaction(body, provider)); exports.sendBscDeployMultiTokenTransaction = sendBscDeployMultiTokenTransaction; const sendBscMintMultiTokenTransaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareBscMintMultiTokenSignedTransaction(body, provider), body.signatureId); exports.sendBscMintMultiTokenTransaction = sendBscMintMultiTokenTransaction; const sendBscMintMultiTokenBatchTransaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareBscMintMultiTokenBatchSignedTransaction(body, provider), body.signatureId); exports.sendBscMintMultiTokenBatchTransaction = sendBscMintMultiTokenBatchTransaction; /** * Send Bsc BEP721 mint transaction to the blockchain with cashback details. This method broadcasts signed transaction to the blockchain. * This operation is irreversible. * @param body content of the transaction to broadcast * @param provider url of the Bsc Server to connect to. If not set, default public server will be used. * @returns transaction id of the transaction in the blockchain */ const sendMintBepCashback721Transaction = async (body, provider) => blockchain_1.bscBroadcast(await exports.prepareBscMintBepCashback721SignedTransaction(body, provider), body.signatureId); exports.sendMintBepCashback