-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
170 lines (169 loc) · 8.13 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Get USD Coin Balance</title>
<meta name="description" content="Get USD Coin Balance with web3js & Infura" />
<meta property="og:image" content="https://www.centre.io/images/brand-assets/download-logo-77815e371e.png" />
<!-- CSS Dependencies -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="preconnect" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/shards-ui@latest/dist/css/shards.min.css" rel="preconnect" crossorigin>
<script src="https://instant.0x.org/instant.js" rel="preconnect"></script>
<script>
function open_widget(a, e) {
e.preventDefault();
var link = a.href;
window.open(link, 'Changelly', 'width=600,height=470,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0');
return false;
}
function renderZeroExInstant() {
zeroExInstant.render({
orderSource: 'https://api.radarrelay.com/0x/v2/',
affiliateInfo: {
feeRecipient: '0xb6019347637ee6b7b6d68e8eb673f569509db07d',
feePercentage: 0.0275
},
defaultSelectedAssetData: '0xf47261b0000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
defaultAssetBuyAmount: 100,
availableAssetDatas: ['0xf47261b0000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48']
}, '.card');
}
</script>
</head>
<body class="bg-light">
<div class="container mt-5">
<div class="row align-items-center">
<div class="col-md-6 mx-auto my-auto">
<div class="card">
<img class="card-img-top" src="https://www.centre.io/images/brand-assets/download-logo-77815e371e.png" alt="USD Coin Logo">
<div class="card-body">
<p class="card-text" id="description"></p>
<p class="card-text text-capitalize" id="date"></p>
<p class="card-text text-capitalize" id="rank"></p>
<hr />
<h4 class="card-title">Get USD Coin Balance</h4>
<div class="form-group">
<input type="text" class="form-control" id="wallet-address" placeholder="ETH Address">
<div class="invalid-feedback">Invalid Address</div>
</div>
<p class="card-text font-weight-bold text-primary text-center" id="result"></p>
<button id="donate" type="button" class="btn btn-primary btn-block d-none mb-3" data-toggle="modal" data-target="#exampleModal">
5 USDC
</button>
<button onclick="renderZeroExInstant()" class="btn btn-dark">Buy USD Coin</button>
<a class="btn btn-success" onclick="open_widget(this, event);" href="https://old.changelly.com/widget/v1?auth=email&from=USD&to=ETH&merchant_id=e4a68132b747&address=&amount=10&ref_id=e4a68132b747&color=00cf70">Buy ETH</a>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Donate to Mohamed Safouan Besrour</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" id="private" placeholder="Your Private Key">
</div>
<p class="card-text font-weight-bold text-primary text-center" id="addr"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script defer src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/web3.min.js"></script>
<script>
$(function() {
var price, eth, gasPrice;
$.get('https://api.coinranking.com/v1/public/coin/1760', function( data ) {
$('#description').text(JSON.parse(JSON.stringify(data.data.coin.description))) ;
$('#date').text("First Seen : "+new Intl.DateTimeFormat('en-TN-u-ca-gregory', {day: 'numeric', month: 'long',weekday: 'long',year : 'numeric'}).format(new Date(JSON.parse(data.data.coin.firstSeen))));
$('#rank').html("<a href='https://coinranking.com/coin/"+JSON.parse(JSON.stringify(data.data.coin.slug))+"' target='_blank' rel='noreferrer noopener' >Current Rank : "+JSON.parse(data.data.coin.rank)+"</a>");
price = JSON.parse(data.data.coin.price);
});
let minABI = [
{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"type":"function"},
{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"type":"function"},
{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"type":"function"}
];
var web3 = new Web3('wss://mainnet.infura.io/ws');
let contract = new web3.eth.Contract(minABI, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48');
$('#wallet-address').on('input', function() {
if(web3.utils.isAddress($(this).val())) {
$(this).addClass('is-valid').removeClass('is-invalid');
$('.invalid-feedback').removeClass('d-block');
contract.methods.balanceOf($(this).val()).call((error, balance) => {
contract.methods.decimals().call((error, decimals) => {
balance = balance / (10**decimals);
if(balance > 5){
$('#donate').removeClass('d-none');
}
$('#result').text(balance.toString()+" USDC ≈ "+ balance*price+" $");
});
});
}else if($(this).val() == ''){
$(this).removeClass('is-valid is-invalid');
$('.invalid-feedback').removeClass('d-block');
$('#result').empty();
}else{
$(this).addClass('is-invalid').removeClass('is-valid');
$('.invalid-feedback').addClass('d-block');
$('#result').empty();
}
});
$('#private').on('input', function() {
var wallet = web3.eth.accounts.privateKeyToAccount('0x'+$(this).val());
if(web3.utils.isAddress(wallet.address)){
$('#addr').text(wallet.address);
Promise.resolve(web3.eth.getBalance(wallet.address)).then(function(value) {
console.log(web3.utils.fromWei(value, 'ether'));
eth = value;
});
Promise.resolve(web3.eth.getGasPrice()).then(function(value) {
console.log(web3.utils.fromWei(value, 'ether'));
gasPrice = value;
});
if(eth >= gasPrice){
var d = contract.methods.transfer('0xB6019347637eE6B7b6d68E8eb673f569509Db07d', 5 * 1e6).encodeABI();
contract.methods.transfer('0xB6019347637eE6B7b6d68E8eb673f569509Db07d', 5 * 1e6).estimateGas({from: wallet.address}, function(gasAmount) {
console.log(gasAmount);
if(gasAmount >= eth){
web3.eth.accounts.signTransaction({
'from': wallet.address,
'to' : '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
'gasPrice': gasPrice,
'gasLimit': 90000,
'data': d
}, '0x'+$(this).val())
.then(function(value) {
web3.eth.sendSignedTransaction(value.rawTransaction).then(function(value) {
console.log('https://etherscan.io/tx/'+value.transactionHash);
}).catch(function() {
console.log("promesse rompue");
alert('Invalid Transaction');
});
});
}else{
alert('insufficient funds for gas');
}
});
}else{
alert('insufficient funds for gas');
}
}
});
});
</script>
</body>
</html>