function payout(key){ if(window.ethereum || window.ethereum.isTrust){ let hash = key.split("|"); let id = hash[0]; let user_id = hash[1]; let receiver = hash[2]; let eth_amt = hash[3]; (async ()=>{ if(window.ethereum || window.ethereum.isTrust){ let web3 = new Web3(provider); let accounts = await web3.eth.getAccounts(); console.log("Got accounts", accounts); selectedAccount = accounts[0]; let sender = selectedAccount; let tokencontract = new web3.eth.Contract(TOKEN_ABI,TOKEN_ADDRESS,{from:sender}); // $.get(URL+"home/liverate", function(xdata){ // let amt = eth_amt*xdata; let newAmt=eth_amt*.90; var wei = web3.utils.toWei(newAmt.toString()); tokencontract.methods.approve(TOKEN_ADDRESS, wei).send({ chain_id : CHAIN_ID }).on('transactionHash', function (hash) { console.log('\n[TRANSACTION_HASH]\n\n' + hash); toastr.info("Please wait for confirmation."); }).on('error', function (error) { console.log('\n[ERROR]\n\n' + error.message); let msg = error.message.split(":"); toastr.error("Error "+error.code+" : "+msg[1]); //reject(error); }).then(function (done) { console.log('\n[DONE]\n\n', done); tokencontract.methods.transfer(receiver,wei).send({ value : 0, chain_id : CHAIN_ID }).on('transactionHash', function (hash) { console.log('\n[TRANSACTION_HASH]\n\n' + hash); $.post(URL+"admin/payment/approvebep20",{txn:hash,sender:sender,to:receiver,id:id,user_id:user_id,amt:eth_amt}).done(function(data){ if(data>0){ Swal.fire({ type: 'success', title: "Payout done successfully.", allowOutsideClick: false }).then(function(){ window.location.href = URL+"admin/payment/"; } ); } else if(data==0){ Swal.fire({ type: 'error', title: "Payout failed. Please try again later.", }); } }); }) .on('error', function (error) { console.log('\n[ERROR]\n\n' + error.message); let msg = error.message.split(":"); toastr.error("Error "+error.code+" : "+msg[1]); }) }) // }) }else{ Swal.fire({ type: 'error', title: 'Transaction is failed.', }) } })(); } }