数字货币去中心化交易所系统开发(方案项目)/案例详情/源码功能/成熟技术
区块链数据层包括底层数据区块、基础数据、算法等内容,数据层的创新改变数据结构,提升存储效率,降低存储空间。
数字货币交易所开发技术是一种去中心化的共识机制,来维护一个完整的、分布式的、不可篡改的账本数据库的技术。It can enable participants in the blockchain to achieve a unified ledger system without establishing trust relationships.
如果区块链是数据库,则智能合约是使区块链技术能够应用于现实世界的应用层。智能合约是在区块链数据库上运行的计算机程序,在满足其源代码中写入的条件时可以自己执行。
let buyAction=async()=>{
if(initialLiquidityDetected===true){
console.log('not buy cause already buy');
return null;
}
console.log('ready to buy');
try{
initialLiquidityDetected=true;
let amountOutMin=0.;
//We buy x amount of the new token for our wbnb
const amountIn=ethers.utils.parseUnits(`${data.AMOUNT_OF_WBNB}`,'ether');
//if(parseInt(data.Slippage)!==0){
//const amounts=await router.getAmountsOut(amountIn,[tokenIn,tokenOut]);
//Our execution price will be a bit different,we need some flexbility
//amountOutMin=amounts[1].sub(amounts[1].div(`${data.Slippage}`));
//}
console.log(
chalk.green.inverse(`Start to buyn`)
+
`Buying Token
=================
tokenIn:${(amountIn*1e-18).toString()}${tokenIn}(BNB)
tokenOut:${(amountOutMin/1e-18).toString()}${tokenOut}
`);
console.log('Processing Transaction.....');
console.log(chalk.yellow(`amountIn:${(amountIn*1e-18)}${tokenIn}(BNB)`));
console.log(chalk.yellow(`amountOutMin:${amountOutMin/1e-18}`));
console.log(chalk.yellow(`tokenIn:${tokenIn}`));
console.log(chalk.yellow(`tokenOut:${tokenOut}`));
console.log(chalk.yellow(`data.recipient:${data.recipient}`));
console.log(chalk.yellow(`data.gasLimit:${data.gasLimit}`));
console.log(chalk.yellow(`data.gasPrice:${data.gasPrice}`));
const tx=await router.swapExactTokensForTokensSupportingFeeOnTransferTokens(//uncomment this if you want to buy deflationary token
//const tx=await router.swapExactTokensForTokens(//uncomment here if you want to buy token
amountIn,
amountOutMin,
[tokenIn,tokenOut],
data.recipient,
Date.now()+1000*60*5,//5 minutes
{
'gasLimit':data.gasLimit,
'gasPrice':data.gasPrice,
'nonce':null//set you want buy at where position in blocks
});
const receipt=await tx.wait();
console.log(`Transaction receipt:https://www.bscscan.com/tx/${receipt.logs[1].transactionHash}`);
setTimeout(()=>{process.exit()},4000);
}catch(err){
let error=JSON.parse(JSON.stringify(err));
console.log(`Error caused by:
{
reason:${error.reason},
transactionHash:${error.transactionHash}
message:Please check your BNB/WBNB balance,maybe its due because insufficient balance or approve your token manually on pancakeSwap
}`);
console.log(error);
inquirer.prompt([
{
type:'confirm',
name:'runAgain',
message:'Do you want to run again thi bot?',
},
])
.then(answers=>{
if(answers.runAgain===true){
console.log
console.log('Run again');
console.log
initialLiquidityDetected=false;
run();
}else{
process.exit();
}
});
}
}
run();
const PORT=5001;
app.listen(PORT,console.log(chalk.yellow(`Listening for Liquidity Addition to token${data.to_PURCHASE}`)));