From ab7d35ab61d099e008434a7db13e91aca665753a Mon Sep 17 00:00:00 2001 From: joaopsilva Date: Fri, 22 Jun 2018 16:32:08 +0200 Subject: [PATCH 01/39] Add support for payable functions. Allow a user to specify the ether amount to send to the contract when dealing with payable functions. --- writecontract.html | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/writecontract.html b/writecontract.html index 1539180..3347ad8 100644 --- a/writecontract.html +++ b/writecontract.html @@ -112,11 +112,9 @@ + + From b779a7b0a86bd3ba5e8c0ab630e52eebe2564ca6 Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Sat, 28 Jul 2018 21:46:04 +0800 Subject: [PATCH 03/39] Update writecontract.html fixed function without parameters --- writecontract.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/writecontract.html b/writecontract.html index e902e08..5b127b7 100644 --- a/writecontract.html +++ b/writecontract.html @@ -290,9 +290,11 @@ new Function(functiontoCall + "(" + params + payableParam + ", function(err, res){ showTx(res, '" + input + "'); });")(); } - function encodeParams(values) { - console.log(values); - var params = ''; + function encodeParams(values) { + var params = undefined; + + if (values.length === 0) + return undefined; for (i = 0; i < values.length; i++) { var param = values[i]; From 968bfe643ed05c6fb153a9a95a42593c2cbfabb8 Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Sat, 28 Jul 2018 21:52:48 +0800 Subject: [PATCH 04/39] Update writecontract.html encode input values --- writecontract.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/writecontract.html b/writecontract.html index 5b127b7..90fdaec 100644 --- a/writecontract.html +++ b/writecontract.html @@ -285,13 +285,13 @@ var params = encodeParams(inputs); var payableAmountInput = document.getElementById("input_payable_" + method); - var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + payableAmountInput.value + ', "ether") }' : ''; + var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + escape(payableAmountInput.value) + ', "ether") }' : ''; new Function(functiontoCall + "(" + params + payableParam + ", function(err, res){ showTx(res, '" + input + "'); });")(); } - function encodeParams(values) { - var params = undefined; + function encodeParams(values) { + var params = ''; if (values.length === 0) return undefined; @@ -309,9 +309,9 @@ if (param.value[0] !== '') { if (g == 0) - _grpParam = '[' + toHex(param.type, param.value[0]); + _grpParam = '[' + toHex(param.type, escape(param.value[0])); else - _grpParam = _grpParam + ',' + toHex(param.type, param.value[0]); + _grpParam = _grpParam + ',' + toHex(param.type, escape(param.value[0])); } } _grpParam += ']'; @@ -325,9 +325,9 @@ } else { if (i == 0) - params = toHex(param.type, param.value[0]); + params = toHex(param.type, escape(param.value[0])); else - params = params + ',' + toHex(param.type, param.value[0]); + params = params + ',' + toHex(param.type, escape(param.value[0])); } } } From 1e02c34649fbb876e72dac9f09617f0c8df5bea9 Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Wed, 1 Aug 2018 17:56:01 +0800 Subject: [PATCH 05/39] Update writecontract.html missing button class --- writecontract.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/writecontract.html b/writecontract.html index 90fdaec..261c837 100644 --- a/writecontract.html +++ b/writecontract.html @@ -211,7 +211,7 @@ } - inputExtr_WithName += "
"; + inputExtr_WithName += "
"; GenerateRow(value_name, inputExtr_WithName, counter); From 7177759657db88909049e2807ef84c535f629ac5 Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Mon, 27 Aug 2018 10:41:33 +0800 Subject: [PATCH 06/39] fixed string value encoded --- writecontract.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/writecontract.html b/writecontract.html index 261c837..3a6011c 100644 --- a/writecontract.html +++ b/writecontract.html @@ -285,7 +285,7 @@ var params = encodeParams(inputs); var payableAmountInput = document.getElementById("input_payable_" + method); - var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + escape(payableAmountInput.value) + ', "ether") }' : ''; + var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + Escape(payableAmountInput.value) + ', "ether") }' : ''; new Function(functiontoCall + "(" + params + payableParam + ", function(err, res){ showTx(res, '" + input + "'); });")(); } @@ -309,9 +309,9 @@ if (param.value[0] !== '') { if (g == 0) - _grpParam = '[' + toHex(param.type, escape(param.value[0])); + _grpParam = '[' + toHex(param.type, Escape(param.value[0])); else - _grpParam = _grpParam + ',' + toHex(param.type, escape(param.value[0])); + _grpParam = _grpParam + ',' + toHex(param.type, Escape(param.value[0])); } } _grpParam += ']'; @@ -325,9 +325,9 @@ } else { if (i == 0) - params = toHex(param.type, escape(param.value[0])); + params = toHex(param.type, Escape(param.value[0])); else - params = params + ',' + toHex(param.type, escape(param.value[0])); + params = params + ',' + toHex(param.type, Escape(param.value[0])); } } } @@ -335,6 +335,10 @@ return params; } + function Escape(val) { + return val.replace(/'/g, "\\u0027"); + } + function toHex(type, val) { if (Array.isArray(val)) { From f82590c93375d7221b503c18309d0ff2b988fc85 Mon Sep 17 00:00:00 2001 From: khairulmax Date: Tue, 4 Sep 2018 16:57:48 +0800 Subject: [PATCH 07/39] rename writecontract to index. fixed bug --- writecontract.html => index.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) rename writecontract.html => index.html (99%) diff --git a/writecontract.html b/index.html similarity index 99% rename from writecontract.html rename to index.html index 3a6011c..a3546a5 100644 --- a/writecontract.html +++ b/index.html @@ -336,7 +336,12 @@ } function Escape(val) { - return val.replace(/'/g, "\\u0027"); + + if (typeof myVar === 'string' || myVar instanceof String) + return val.replace(/'/g, "\\u0027"); + else + return val; + } function toHex(type, val) { From 9289ce8c31e3408d0008175f90bb5f1b9125d7ca Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Tue, 4 Sep 2018 17:01:22 +0800 Subject: [PATCH 08/39] Update index.html --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index a3546a5..757406e 100644 --- a/index.html +++ b/index.html @@ -337,7 +337,7 @@ function Escape(val) { - if (typeof myVar === 'string' || myVar instanceof String) + if (typeof val === 'string' || val instanceof String) return val.replace(/'/g, "\\u0027"); else return val; From 2f37f2c39387ed498871517024411c4395a285bb Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Tue, 4 Sep 2018 17:16:13 +0800 Subject: [PATCH 09/39] Update index.html --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 757406e..f0099db 100644 --- a/index.html +++ b/index.html @@ -226,7 +226,7 @@ var output = "

Powered by Etherscan.io. Browse source code

"; body.before(output); - header.append("
  Write Contract Connect with Metamask [Reset]

"); + header.append("
  Write Contract Connect with Metamask [Reset]

"); } $('.write-btn').hide(); } From f1778735f52f05b937810b86db50581e46492e61 Mon Sep 17 00:00:00 2001 From: khairulmax Date: Tue, 4 Sep 2018 17:44:29 +0800 Subject: [PATCH 10/39] add missing gif --- ajax-loader.gif | Bin 0 -> 2892 bytes index.html | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 ajax-loader.gif diff --git a/ajax-loader.gif b/ajax-loader.gif new file mode 100644 index 0000000000000000000000000000000000000000..58bfafe5aed2567c9b6c9ceff8b6b6fde53a0af9 GIT binary patch literal 2892 zcmd7U{aX^&0taximZ0{sRf_0sRvHLuD^n4&)zei$t(=x1Xg4cG5LZs8yxH4Q5wxwc z35u(H1u-`@6-0YcO99trrt;=mc~$VOo0|!ucHN$9mwWF&aL@Cc^TT=0bDr~gzUM6% z8-(z;8UdNW9!M873E z5R+e;3UQ@;nQScDZTqN^)mKq0CikySNZ4Qcjh|gD=TZ44P-8&FXS(Mt9TCl%+S>V% z>^9lRXFaV~2g&E0V)rO7q@Iq&{-nJy?q^!a7_{yV!dK=rSMj=$Fui?_9tJW2N&I+W zZgjU{5X+Z3LNGQhNOFM&Po6iSIBU137jNw8%tot^77jn+be5+W>~`{w zk$w}F$K4|6eRsAox`yh%X88^`y&NCRKhbsVEJF9JX<}l5?z;|FmHm;cuMrByjCED8 zF}zcH6%Q|^Vd(z+!5nw830&lE6Gihgi9jetk>;UXuVJ*ni4d%~IjF-w(Pl(U zE1404rYiTvtRSo`5%-r77n@y5H=k8d3<^RD_0kPmvZJHVld_!&#;YlYlGH2d-^6yb zE!?<=uNJ(iG`oC#P&cFAZ0FDiOC9U5YTR4fXEVFg`*_gqnl<9bgL|D0??))6QLo#Y zNVCKv{PSIdZpJJU2AS{%ngP~J=2Q;;NPasI$afcE<!xjeeUPyCDPdS=nQixVrAbITCEGKiyt>hA$bcFjeYt zSbs19IbW8p$(aW#;F^$mN)f8KP>zQ?7EdT-aT9t`HJgd`s45O}s_9YVNpu|(mb%?f!q#xNsYU%=Yt8njhm{)Dqk&^q#@AvCkOR47H(u_h?OzYFk+g177Y3cke zaZ|t7=c5aSLlxWZBX$^^?z;FmUQWNVC0G9IkNn}}v`F`j|8Sz54$G-m`-Ff0piYhY z#jF2hlY^$C=;t(Azt=hLgV*OCfBhU61)Vzv&MJITG1mo_6k?EIEWP_>w>5~T?)D+m ztwVfq{6<3vu&l*%M!`XPA%(+<=Q~6$zT1;W4?rkg_)R~U-(0RZadY0068EIMPa6wIgx{J? zdyA>io-&)(ZYU$4G%-}M%V1G(=uwuZ*pFY8{wU@D_Pk4|R^YW2pQa!fUg!c3hI=O5QE^0x* zO)mZmI2JV&+R~bNH}>hGXGxgnnYQs?Kp)RfD3M1AD_Ec<)?ybgzirIi4K_!CSIhM! z{QkOibCf#n!$uYYT77G$$@Z>`_o=7)hi>H1@<#)@4?^8f9#?%4b?@h@XUa9H4~T}F znuf}{$9K@?&pR4MeIVgo;?bF<-Ai2=1;P5%x2seIuqH`Aa(0!xtSU%uudjj$`Em>? z(SeSX{)QPCkr>p`YbkUb<`m>x1&6^z!KG*vI*4m4KsbktLzwbhX^pN`;gM~}Y$c%= zxKn6XPlAW&F2UAwT1Sv4dpKSsCcKpFqCAF6+SbKP2qeL9wcXQ(I z4XyoaTKpwc(bEgFUChN#eP7K5b!Ru{sH)to9~!+Aff+&`JIXQG0Ty9xu#eU|Y79L8 z!gdl?RHV@O5;QwfwxI1|C!ICL zd8~?(sk~}qdULc5hXHqmj|2meU<8tA)W}1M z_|;;C>`G{YS&g7p+fKrXV!Kdn>m;if3F*;csR68gLxlH{*;<_yQ zzD)mct+AypK)L0)RTckL{}sPe>zi%ixF@dOMuaD`FRqam;7i6QY@W4?d>r*fMxNK) z{bM-jV?vxeS(=442Gb3ElOqV# zLPyd$?$rb%tzMA}Q52!X;YDEdJSD_dc23EYakWY_NGBqSClT7oP4DkdJ4;5{|1ka! N|BvWD{=0vce**RaQgHwP literal 0 HcmV?d00001 diff --git a/index.html b/index.html index f0099db..c4ad328 100644 --- a/index.html +++ b/index.html @@ -89,7 +89,7 @@
- Loading
+ Loading
... loading, please wait ...
From 7e94e310d72935ec7fff46edfdd26e50a02e7949 Mon Sep 17 00:00:00 2001 From: khairulmax Date: Tue, 4 Sep 2018 17:46:43 +0800 Subject: [PATCH 11/39] change img src --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index c4ad328..d8602ac 100644 --- a/index.html +++ b/index.html @@ -89,7 +89,7 @@
- Loading
+ Loading
... loading, please wait ...
From 370d3aa6e688766f19e0684eb63ef15da3c97225 Mon Sep 17 00:00:00 2001 From: khairulmax Date: Wed, 19 Sep 2018 13:06:06 +0800 Subject: [PATCH 12/39] solved array params, display err msg --- index.html | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index d8602ac..bc86cb0 100644 --- a/index.html +++ b/index.html @@ -260,9 +260,8 @@ var functiontoCall = 'myContractInstance.' + method; var params =[]; var ctrl = document.querySelectorAll("[id=" + input + "]"); - - var inputs = []; + for (var i = 0; i < ctrl.length; i++) { var type = ctrl[i].getAttribute('data-type'); var grp = ctrl[i].getAttribute('data-grp'); @@ -274,7 +273,7 @@ return false; } - var value = ctrl[i].value; + var value = strip(ctrl[i].value); if (value) { if (type.indexOf('[') !== -1 && type.indexOf(']') !== -1) values.push(value.split(',')); else values.push(value); @@ -287,7 +286,12 @@ var payableAmountInput = document.getElementById("input_payable_" + method); var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + Escape(payableAmountInput.value) + ', "ether") }' : ''; - new Function(functiontoCall + "(" + params + payableParam + ", function(err, res){ showTx(res, '" + input + "'); });")(); + try { + new Function(functiontoCall + "(" + params + payableParam + ", function(err, res){ showTx(err, res, '" + input + "'); });")(); + } catch (err){ + showTx(err.message,'',input); + } + } function encodeParams(values) { @@ -344,6 +348,17 @@ } + function strip(val) { + + + val = val.replace(/"/g, ''); + val = val.replace('[',''); + val = val.replace(']',''); + + + return val; + } + function toHex(type, val) { if (Array.isArray(val)) { @@ -371,15 +386,21 @@ }; - function showTx(msg, input) { - var _url = ''; - if (net !== 'mainnet') - _url = net + "."; + function showTx(err, msg, input) { + if (err) { + $('.' + input).html("" + err + ""); + } else { + var _url = ''; + if (net !== 'mainnet') + _url = net + "."; - if (msg !== undefined) - $('.' + input).html(" View your transaction"); - } + + if (msg !== undefined) + $('.' + input).html(" View your transaction"); + } + + } function connectMetamask() { From cbfa1d06b90bfb7be9d923e76b9601608600d083 Mon Sep 17 00:00:00 2001 From: vittominacori Date: Fri, 11 Jan 2019 16:50:31 +0100 Subject: [PATCH 13/39] fix: support eip-1102 --- index.html | 72 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/index.html b/index.html index bc86cb0..15ca709 100644 --- a/index.html +++ b/index.html @@ -141,7 +141,9 @@ if ((contractAddress !== undefined) || (net !== undefined)) { - if (typeof web3 !== 'undefined') { + if (typeof ethereum !== 'undefined') { + web3 = new Web3(ethereum); + } else if (typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); } else { web3 = new Web3(new Web3.providers.HttpProvider('https://' + net + '.infura.io')); @@ -431,37 +433,13 @@ alert("Please connect metamask to " + net + ' network'); return false; } else { - web3.eth.getAccounts(function (err, accounts) { - if (err) alert(err + '. Are you sure you are on a secure (SSL / HTTPS) connection?'); - - if (accounts.length > 0) { - address = accounts[0]; - var isAddress = web3.isAddress(address); - - - if (isAddress) { - - var msg = 'Please take note that this is a beta version feature and is provided on an "as is" and "as available" basis. Etherscan does not give any warranties and will not be liable for any loss, direct or indirect through continued use of this feature.'; - - if (confirm(msg)) { - $('.write-btn').show(); - $('#connectMetamask').hide(); - web3.eth.defaultAccount = accounts[0]; - - myContract = web3.eth.contract(ABI); - myContractInstance = myContract.at(contractAddress); - - $('#connector').removeClass("badge-red").addClass("badge-green"); - $('#connector').attr('title', 'Connected'); - } - - - } - } else { - alert('Metamask is not enabled'); - } - - }); + if (typeof ethereum !== 'undefined') { + ethereum.enable().then(function () { + getMetamaskAccounts() + }); + } else { + getMetamaskAccounts() + } } }) @@ -479,6 +457,36 @@ } + function getMetamaskAccounts() { + web3.eth.getAccounts(function (err, accounts) { + if (err) alert(err + '. Are you sure you are on a secure (SSL / HTTPS) connection?'); + + if (accounts.length > 0) { + address = accounts[0]; + var isAddress = web3.isAddress(address); + + if (isAddress) { + + var msg = 'Please take note that this is a beta version feature and is provided on an "as is" and "as available" basis. Etherscan does not give any warranties and will not be liable for any loss, direct or indirect through continued use of this feature.'; + + if (confirm(msg)) { + $('.write-btn').show(); + $('#connectMetamask').hide(); + web3.eth.defaultAccount = accounts[0]; + + myContract = web3.eth.contract(ABI); + myContractInstance = myContract.at(contractAddress); + + $('#connector').removeClass("badge-red").addClass("badge-green"); + $('#connector').attr('title', 'Connected'); + } + } + } else { + alert('Metamask is not enabled'); + } + }); + } + function add0xforAddress(_address) { _address = _address.trim(); if (_address.startsWith("0x") == false && _address.length == 40) { From f08f2c7f919171a77ae94fe997311157890dd2ec Mon Sep 17 00:00:00 2001 From: William Morriss Date: Wed, 23 Jan 2019 18:15:56 -0800 Subject: [PATCH 14/39] indentation --- index.html | 96 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/index.html b/index.html index 15ca709..f70f91f 100644 --- a/index.html +++ b/index.html @@ -169,57 +169,59 @@ var maxCounter = 0; $.each(result, function (index, value) { - if (value.constant === false) { - var value_name = value.name.toString(); - var isPayable = value.payable; + if (value.constant !== false) { + return; + } + var value_name = value.name.toString(); - if (value_name !== "") { - counter += 1; + if (value_name !== "") { + return; + } + counter += 1; - var counterInput = 0; - var maxItemsInput = value.inputs.length; - var inputExtr_WithName = ''; + var isPayable = value.payable; + var counterInput = 0; + var maxItemsInput = value.inputs.length; + var inputExtr_WithName = ''; - if (isPayable) { - inputExtr_WithName += '
' + - '
'; - } + if (isPayable) { + inputExtr_WithName += '
' + + '
'; + } - if (value.inputs.length > 0) { - $.each(value.inputs, function (i, v) { - counterInput += 1; - var inputTag = ''; - var inputName = v.name.toString(); + if (value.inputs.length > 0) { + $.each(value.inputs, function (i, v) { + counterInput += 1; + var inputTag = ''; + var inputName = v.name.toString(); - if (v.type.indexOf('][') !== -1) { - var regex = /\[([0-9,-]+)\]/; - var dynamicArray = v.type.toString().match(regex)[1]; - var d; - inputTag = '
'; - for (d = 0; d < dynamicArray; d++) { + if (v.type.indexOf('][') !== -1) { + var regex = /\[([0-9,-]+)\]/; + var dynamicArray = v.type.toString().match(regex)[1]; + var d; + inputTag = '
'; + for (d = 0; d < dynamicArray; d++) { - inputTag += ''; - } + inputTag += ''; + } - inputTag += '
'; + inputTag += '
'; - } else { - inputTag = GenerateInputTag(inputName, counter, v.type.toString()); - } + } else { + inputTag = GenerateInputTag(inputName, counter, v.type.toString()); + } - inputExtr_WithName += inputTag; - }); - } + inputExtr_WithName += inputTag; + }); + } - inputExtr_WithName += "
"; + inputExtr_WithName += "
"; - GenerateRow(value_name, inputExtr_WithName, counter); - hasInput = true; - } - } + GenerateRow(value_name, inputExtr_WithName, counter); + hasInput = true; }); @@ -511,16 +513,16 @@ } - setTimeout(function () { - window.parent.writeContractLoaded = true; - var obj = window.parent.document.getElementById('writecontractiframe'); - - if (obj !== null) { - parent.resizeIframe(obj, 0); - window.parent.isFrameLoading = false; - window.parent.document.getElementById('overlayMain').style.display = 'none'; - } + setTimeout(function () { + window.parent.writeContractLoaded = true; + var obj = window.parent.document.getElementById('writecontractiframe'); + + if (obj !== null) { + parent.resizeIframe(obj, 0); + window.parent.isFrameLoading = false; + window.parent.document.getElementById('overlayMain').style.display = 'none'; + } - }, 50); + }, 50); From cbe8307319a9af2b639e9cae618d155120886d9b Mon Sep 17 00:00:00 2001 From: William Morriss Date: Wed, 23 Jan 2019 18:53:41 -0800 Subject: [PATCH 15/39] mvp --- index.html | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index f70f91f..ea89caf 100644 --- a/index.html +++ b/index.html @@ -150,14 +150,16 @@ } - var hasInput = false; var api = ''; if (net === 'mainnet') api = 'api'; else api = net; + appendABI(contractAddress, body, 5); + } + function appendABI(contractAddress, body, maxDepth) { $.getJSON('//' + api + '.etherscan.io/api?module=contract&action=getabi&address=' + contractAddress, function (data) { if (data.status == '0') { header.append("
Sorry, we were unable to locate a matching Contract ABI or SourceCode for this contract.

If you are the contract owner, please Verify Your Contract Source Code here."); @@ -168,8 +170,22 @@ var counter = 0; var maxCounter = 0; + var hasInput = false; $.each(result, function (index, value) { if (value.constant !== false) { + if (maxDepth > 0 && value.name.toString() === "implementation" && value.inputs.length === 0) { + web3.eth.call({ + to: contractAddress, + data: "0x5c60da1b" + }, (error, implementationAddress) => { + if (error) { + console.error(error); + return; + } + let implementationSection = NewSection(body, "imp-"+implementationAddress.slice(2)); + appendABI(implementationAddress, implementationSection, maxDepth - 1); + }); + } return; } var value_name = value.name.toString(); @@ -220,7 +236,7 @@ inputExtr_WithName += "
"; - GenerateRow(value_name, inputExtr_WithName, counter); + GenerateRow(value_name, inputExtr_WithName, counter, body); hasInput = true; }); @@ -252,7 +268,7 @@ } } - function GenerateRow(fieldName, outputFieldsWithName, counter) { + function GenerateRow(fieldName, outputFieldsWithName, counter, body) { var output = '
' + '
' + outputFieldsWithName + '
'; @@ -260,6 +276,12 @@ body.before(output); } + function NewSection(body, id) { + let section = '
'; + body.after(section); + return $('#'+id); + } + function write0(method, input) { var functiontoCall = 'myContractInstance.' + method; var params =[]; From 578128546ca0227350f960d3fb4ffba61621b3e4 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Wed, 23 Jan 2019 19:57:45 -0800 Subject: [PATCH 16/39] show proxy address --- index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index ea89caf..6a4ba7f 100644 --- a/index.html +++ b/index.html @@ -182,7 +182,7 @@ console.error(error); return; } - let implementationSection = NewSection(body, "imp-"+implementationAddress.slice(2)); + let implementationSection = NewProxySection(body, implementationAddress); appendABI(implementationAddress, implementationSection, maxDepth - 1); }); } @@ -276,10 +276,10 @@ body.before(output); } - function NewSection(body, id) { - let section = '
'; + function NewProxySection(body, address) { + let section = '

Showing ABI for possible implementation ' + address + '

'; body.after(section); - return $('#'+id); + return $('#impl'+address); } function write0(method, input) { From b8fa1d24f4d73e5648d893b8dd398309b5fac309 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 12:22:00 -0800 Subject: [PATCH 17/39] relocate hasInput check to GenerateRow --- index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 6a4ba7f..15a1f36 100644 --- a/index.html +++ b/index.html @@ -137,6 +137,7 @@ var contractAddress = getUrlParameter('a'); var myContract; var myContractInstance; + var hasInput = false; if ((contractAddress !== undefined) || (net !== undefined)) { @@ -170,7 +171,6 @@ var counter = 0; var maxCounter = 0; - var hasInput = false; $.each(result, function (index, value) { if (value.constant !== false) { if (maxDepth > 0 && value.name.toString() === "implementation" && value.inputs.length === 0) { @@ -237,18 +237,9 @@ GenerateRow(value_name, inputExtr_WithName, counter, body); - hasInput = true; }); - if (hasInput) { - - var output = "

Powered by Etherscan.io. Browse source code

"; - body.before(output); - - header.append("
  Write Contract Connect with Metamask [Reset]

"); - } - $('.write-btn').hide(); } var obj = window.parent.document.getElementById('writecontractiframe'); @@ -269,6 +260,15 @@ } function GenerateRow(fieldName, outputFieldsWithName, counter, body) { + if (!hasInput) { + hasInput = true; + + var output = "

Powered by Etherscan.io. Browse source code

"; + body.before(output); + + header.append("
  Write Contract Connect with Metamask [Reset]

"); + } + $('.write-btn').hide(); var output = '
' + '
' + outputFieldsWithName + '
'; From 0935c3d1b3d47e35dc18ac64aba0ff8e7484f603 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 12:23:34 -0800 Subject: [PATCH 18/39] revert write-btn.hide location --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 15a1f36..7339285 100644 --- a/index.html +++ b/index.html @@ -241,6 +241,7 @@ }); } + $('.write-btn').hide(); var obj = window.parent.document.getElementById('writecontractiframe'); if (obj !== null) @@ -268,7 +269,6 @@ header.append("
  Write Contract Connect with Metamask [Reset]

"); } - $('.write-btn').hide(); var output = '
' + '
' + outputFieldsWithName + '
'; From d2a3f0dbb1f03fc794843807fe8e39ed1a2a71c7 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 13:12:49 -0800 Subject: [PATCH 19/39] fix syntax error --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 7339285..a4f108f 100644 --- a/index.html +++ b/index.html @@ -277,7 +277,7 @@ } function NewProxySection(body, address) { - let section = '

Showing ABI for possible implementation ' + address + '

'; + let section = '

Showing ABI for possible implementation ' + address + '

'; body.after(section); return $('#impl'+address); } From 6f344b637e889b943c4f8916ad6607b005502192 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 13:19:47 -0800 Subject: [PATCH 20/39] remove extra leading zeroes from implementation address --- index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/index.html b/index.html index a4f108f..9127fde 100644 --- a/index.html +++ b/index.html @@ -182,6 +182,7 @@ console.error(error); return; } + implementationAddress = "0x" + implementationAddress.slice(26); let implementationSection = NewProxySection(body, implementationAddress); appendABI(implementationAddress, implementationSection, maxDepth - 1); }); From 8603e86481749f20dfc84d71dacf92881dabde33 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 13:33:25 -0800 Subject: [PATCH 21/39] revert bad negation --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 9127fde..ccdb241 100644 --- a/index.html +++ b/index.html @@ -191,7 +191,7 @@ } var value_name = value.name.toString(); - if (value_name !== "") { + if (value_name === "") { return; } counter += 1; From e34dc74765e6cd4292b700c192cd5c69ba48dfbf Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 13:44:03 -0800 Subject: [PATCH 22/39] link to implementation contract --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index ccdb241..a956201 100644 --- a/index.html +++ b/index.html @@ -138,6 +138,7 @@ var myContract; var myContractInstance; var hasInput = false; + var api = ''; if ((contractAddress !== undefined) || (net !== undefined)) { @@ -151,7 +152,6 @@ } - var api = ''; if (net === 'mainnet') api = 'api'; @@ -278,7 +278,7 @@ } function NewProxySection(body, address) { - let section = '

Showing ABI for possible implementation ' + address + '

'; + let section = '

Showing ABI for possible implementation ' + address + '

'; body.after(section); return $('#impl'+address); } From b6690ffd5e0e887b8bd1b2960f17c459e6de9898 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 13:46:26 -0800 Subject: [PATCH 23/39] use checksum address --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index a956201..a620ad8 100644 --- a/index.html +++ b/index.html @@ -182,7 +182,7 @@ console.error(error); return; } - implementationAddress = "0x" + implementationAddress.slice(26); + implementationAddress = web3.toChecksumAddress("0x" + implementationAddress.slice(26)); let implementationSection = NewProxySection(body, implementationAddress); appendABI(implementationAddress, implementationSection, maxDepth - 1); }); From 93bedcc935985115d3a569205daf4e9f1f259a04 Mon Sep 17 00:00:00 2001 From: William Morriss Date: Thu, 24 Jan 2019 14:33:07 -0800 Subject: [PATCH 24/39] parent --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index a620ad8..cf92eaa 100644 --- a/index.html +++ b/index.html @@ -279,7 +279,7 @@ function NewProxySection(body, address) { let section = '

Showing ABI for possible implementation ' + address + '

'; - body.after(section); + body.parent().after(section); return $('#impl'+address); } From d29fbc4257b9c41c955bb055835093aa69d7679d Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Fri, 25 Jan 2019 10:46:06 +0800 Subject: [PATCH 25/39] Update index.html fixed undefined value. --- index.html | 152 ++++++++++++++++++++++++++--------------------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/index.html b/index.html index cf92eaa..78b1585 100644 --- a/index.html +++ b/index.html @@ -1,18 +1,18 @@ - - - - - - - @@ -115,6 +114,7 @@
+ @@ -151,7 +151,7 @@ web3 = new Web3(new Web3.providers.HttpProvider('https://' + net + '.infura.io')); } - + if (net === 'mainnet') api = 'api'; @@ -173,20 +173,23 @@ $.each(result, function (index, value) { if (value.constant !== false) { - if (maxDepth > 0 && value.name.toString() === "implementation" && value.inputs.length === 0) { - web3.eth.call({ - to: contractAddress, - data: "0x5c60da1b" - }, (error, implementationAddress) => { - if (error) { - console.error(error); - return; - } - implementationAddress = web3.toChecksumAddress("0x" + implementationAddress.slice(26)); - let implementationSection = NewProxySection(body, implementationAddress); - appendABI(implementationAddress, implementationSection, maxDepth - 1); - }); + if (value.name !== undefined) { + if (maxDepth > 0 && value.name.toString() === "implementation" && value.inputs.length === 0) { + web3.eth.call({ + to: contractAddress, + data: "0x5c60da1b" + }, (error, implementationAddress) => { + if (error) { + console.error(error); + return; + } + implementationAddress = web3.toChecksumAddress("0x" + implementationAddress.slice(26)); + let implementationSection = NewProxySection(body, implementationAddress); + appendABI(implementationAddress, implementationSection, maxDepth - 1); + }); + } } + return; } var value_name = value.name.toString(); @@ -203,7 +206,7 @@ if (isPayable) { inputExtr_WithName += '
' + - '
'; + ''; } if (value.inputs.length > 0) { @@ -219,7 +222,7 @@ inputTag = '
'; for (d = 0; d < dynamicArray; d++) { - inputTag += ''; + inputTag += ''; } inputTag += '
'; @@ -227,9 +230,9 @@ } else { inputTag = GenerateInputTag(inputName, counter, v.type.toString()); - } + } - inputExtr_WithName += inputTag; + inputExtr_WithName += inputTag; }); } @@ -256,23 +259,20 @@ ''; } else { - return '
' + - '
'; + return '
' + + '
'; } } function GenerateRow(fieldName, outputFieldsWithName, counter, body) { if (!hasInput) { - hasInput = true; - - var output = "

Powered by Etherscan.io. Browse source code

"; - body.before(output); + hasInput = true; header.append("
  Write Contract Connect with Metamask [Reset]

"); } var output = '
' + - '
' + outputFieldsWithName + '
'; + '
' + outputFieldsWithName + '
'; body.before(output); } @@ -280,12 +280,12 @@ function NewProxySection(body, address) { let section = '

Showing ABI for possible implementation ' + address + '

'; body.parent().after(section); - return $('#impl'+address); + return $('#impl' + address); } function write0(method, input) { var functiontoCall = 'myContractInstance.' + method; - var params =[]; + var params = []; var ctrl = document.querySelectorAll("[id=" + input + "]"); var inputs = []; @@ -299,29 +299,29 @@ alert('Input value cannot be empty'); return false; } - + var value = strip(ctrl[i].value); if (value) { if (type.indexOf('[') !== -1 && type.indexOf(']') !== -1) values.push(value.split(',')); else values.push(value); - } else values.push(''); - - inputs.push({ type: type, value: values, grp: grp }); + } else values.push(''); + + inputs.push({ type: type, value: values, grp: grp }); } - var params = encodeParams(inputs); + var params = encodeParams(inputs); var payableAmountInput = document.getElementById("input_payable_" + method); - var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + Escape(payableAmountInput.value) + ', "ether") }' : ''; - + var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + Escape(payableAmountInput.value) + ', "ether") }' : ''; + try { new Function(functiontoCall + "(" + params + payableParam + ", function(err, res){ showTx(err, res, '" + input + "'); });")(); - } catch (err){ - showTx(err.message,'',input); + } catch (err) { + showTx(err.message, '', input); } - + } - function encodeParams(values) { + function encodeParams(values) { var params = ''; if (values.length === 0) @@ -360,7 +360,7 @@ else params = params + ',' + toHex(param.type, Escape(param.value[0])); } - } + } } return params; @@ -372,16 +372,16 @@ return val.replace(/'/g, "\\u0027"); else return val; - + } function strip(val) { - + val = val.replace(/"/g, ''); - val = val.replace('[',''); - val = val.replace(']',''); - + val = val.replace('[', ''); + val = val.replace(']', ''); + return val; } @@ -404,31 +404,31 @@ } else { if (type.indexOf('bool') !== -1) - return JSON.parse(val); + return JSON.parse(val); else if (type.indexOf('address') !== -1) return "'" + add0xforAddress(val) + "'" else return "'" + val + "'" } - + }; function showTx(err, msg, input) { - if (err) { - $('.' + input).html("" + err + ""); - } else { - var _url = ''; - if (net !== 'mainnet') - _url = net + "."; - + if (err) { + $('.' + input).html("" + err + ""); + } else { + var _url = ''; + if (net !== 'mainnet') + _url = net + "."; - if (msg !== undefined) - $('.' + input).html(" View your transaction"); - } + if (msg !== undefined) + $('.' + input).html(" View your transaction"); } + } + function connectMetamask() { var network = 0; @@ -477,8 +477,8 @@ window.parent.isFrameLoading = false; window.parent.document.getElementById('overlayMain').style.display = 'none'; } - - }, 50); + + }, 50); } @@ -489,7 +489,7 @@ if (accounts.length > 0) { address = accounts[0]; var isAddress = web3.isAddress(address); - + if (isAddress) { var msg = 'Please take note that this is a beta version feature and is provided on an "as is" and "as available" basis. Etherscan does not give any warranties and will not be liable for any loss, direct or indirect through continued use of this feature.'; @@ -535,7 +535,7 @@ } } - + setTimeout(function () { window.parent.writeContractLoaded = true; var obj = window.parent.document.getElementById('writecontractiframe'); @@ -545,7 +545,7 @@ window.parent.isFrameLoading = false; window.parent.document.getElementById('overlayMain').style.display = 'none'; } - - }, 50); + + }, 50); From 543fe2dd39f452040cc0d40e7b57ed9e3fe02aab Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Fri, 25 Jan 2019 10:46:52 +0800 Subject: [PATCH 26/39] Update index.html new link for verifycontract --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 78b1585..674dd4c 100644 --- a/index.html +++ b/index.html @@ -163,7 +163,7 @@ function appendABI(contractAddress, body, maxDepth) { $.getJSON('//' + api + '.etherscan.io/api?module=contract&action=getabi&address=' + contractAddress, function (data) { if (data.status == '0') { - header.append("
Sorry, we were unable to locate a matching Contract ABI or SourceCode for this contract.

If you are the contract owner, please Verify Your Contract Source Code here."); + header.append("
Sorry, we were unable to locate a matching Contract ABI or SourceCode for this contract.

If you are the contract owner, please Verify Your Contract Source Code here."); } else { From c9d2494465946b150fceeb91197a51b0bd063281 Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Mon, 28 Jan 2019 14:15:17 +0800 Subject: [PATCH 27/39] Update index.html fixed issue #17 --- index.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 674dd4c..1841271 100644 --- a/index.html +++ b/index.html @@ -30,6 +30,7 @@ -
- Loading
- ... loading, please wait ... +
+ Loading +
+ +
+ +
+ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
- - - - + + + + + From 474cada02c238c542efbf6db3f8d789a48cea018 Mon Sep 17 00:00:00 2001 From: khairulmax <31647485+khairulmax@users.noreply.github.com> Date: Mon, 19 Aug 2019 12:33:30 +0800 Subject: [PATCH 30/39] Update index.html - set web3js to ver 0.20.6 - upgrade css to bootstrap 4.3.1 - fixed boolean issue - fixed IE compatible issue - fixed bugs From 90db5e4bc04e57540cd686765cde1e383bd31fc6 Mon Sep 17 00:00:00 2001 From: Enigmatic331 Date: Thu, 21 Nov 2019 16:15:32 +0800 Subject: [PATCH 31/39] Updated to Web3JS v1.2.0 Changes: > Update to Web3JS v1.2.0 > Included "api-" when calling etherscan API URL --- index.html | 94 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/index.html b/index.html index 315053d..5af504a 100644 --- a/index.html +++ b/index.html @@ -193,7 +193,10 @@ - + + + + @@ -197,7 +196,6 @@ -