-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
100 lines (93 loc) · 2.54 KB
/
script.js
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
var contract;
var address = "0x95643B6761397de5882A58210B5787Bb9CC90a75";
var abi = [
{
"inputs": [
{
"internalType": "uint256",
"name": "Amount",
"type": "uint256"
},
{
"internalType": "address",
"name": "sendTo",
"type": "address"
}
],
"name": "Send",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "Withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
},
{
"inputs": [],
"name": "GetBalance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
];
var web3 = new Web3(new Web3.providers.HttpProvider('https://goerli.infura.io/v3/3257f723cdc840198733d629c17c7cd2'));
var contract = new web3.eth.Contract(abi, address);
contract.methods.owner().call().then(function(add){
document.getElementById('myaddress').value = add ;
})
document.getElementById('SendBtn').onclick = sendTransact;
function sendTransact (){
var sendAdd = document.getElementById('inputAddress').value ;
Amt = document.getElementById('amount').value;
var sendAmt = web3.utils.toWei(Amt, 'ether');
// contract.methods.Send(sendAmt,sendAdd).send({from:"0x4A0B6552F1D6fD37abE1d3882e58bdEa522f2942"});
//methods.solidityFunction(parameter...,{from: web3.eth.accounts[0], gas:1000000, value: web3.toWei(0.01, "ether")});
contract.methods.Send(sendAmt,sendAdd).send({from: "0x4A0B6552F1D6fD37abE1d3882e58bdEa522f2942"}).then( alert("Transaction Initiated !"))
// contract.methods.Send().call().then(
// alert("Transaction Initiated !"))
//alert(sendAdd +" "+sendAmt);
}
//Withdraw
document.getElementById('withdrawBtn').onclick = function(){
// contract.methods.Withdraw().send({from : "0x4A0B6552F1D6fD37abE1d3882e58bdEa522f2942"});
//contract.methods.Withdraw().call().then(
// alert("Withdraw procced !")
// )
}
contract.methods.GetBalance().call().then(function (Balance) {
//alert(Balance);
var bal = Balance/1e18 ;
document.getElementById('balance').innerHTML = (bal + " ETH");
})