atomicSwap

<style type="text/css">
    html {
        font-size: 13px;
    }

    body {
        font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
    }

    a {
        color: #3498db;
    }

        a:hover {
            color: #1d6fa5;
        }

    .text-primary {
        color: #3498db !important;
    }

    .btn-link:hover {
        color: #1d6fa5;
        text-decoration: none;
    }

    .card-btn-arrow {
        display: inline-block;
        color: #3498db;
        margin-top: 5px;
    }

    #overlay {
        /*background: #ffffff;*/
        background: rgba(255,255,255,.7);
        color: #666666;
        position: fixed;
        height: 100%;
        width: 100%;
        z-index: 5000;
        top: 0;
        left: 0;
        float: left;
        text-align: center;
        padding-top: 10%;
        display: none;
    }

    .accordion-arrow {
        display: inline-block;
        transition: 0.3s ease-in-out;
    }

    .collapsed .accordion-arrow {
        transform: rotate(-90deg);
    }

    body.dark-mode {
        color: #a2b9c8;
        background-color: #01263f !important;
    }

        body.dark-mode .bg-light {
            background-color: #01263f !important
        }

        body.dark-mode .text-secondary {
            color: #7295ac !important
        }


        body.dark-mode .border, body.dark-mode .border-bottom, body.dark-mode .border-top, body.dark-mode .u-ver-divider--left:after, body.dark-mode .u-ver-divider:after {
            border-color: #013558 !important
        }

        body.dark-mode p {
            color: #a2b9c8
        }

        body.dark-mode .modal-footer, body.dark-mode .modal-header {
            border-color: #013558
        }

        body.dark-mode .card {
            border-color: transparent !important;
            background-color: #012137 !important;
            box-shadow: 0 .5rem 1.2rem rgba(4,76,124,.2)
        }

        body.dark-mode .card-header {
            background-color: #012137 !important;
            border-color: #013558
        }

        body.dark-mode .card-header-title {
            color: #a2b9c8
        }

        body.dark-mode .card-btn {
            color: #a2b9c8
        }

        body.dark-mode .form-control::-webkit-input-placeholder {
            color: #577c93
        }

        body.dark-mode .form-control::-moz-placeholder {
            color: #577c93
        }

        body.dark-mode .form-control::-ms-input-placeholder {
            color: #577c93
        }

        body.dark-mode .form-control::placeholder {
            color: #577c93
        }

        body.dark-mode .link-hover-secondary, body.dark-mode .text-dark, body.dark-mode .text-link, body.dark-mode .text-muted, body.dark-mode .text-white {
            color: #a2b9c8 !important
        }

        body.dark-mode .custom-select, body.dark-mode .form-control, body.dark-mode .input-group-text {
            color: #a2b9c8 !important;
            border-color: #013558 !important;
            background-color: #01263f !important
        }

        body.dark-mode .btn-primary, body.dark-mode .btn-primary:not([href]), body.dark-mode .btn-primary:not([href]):not([href]):not(:disabled):not(.disabled) {
            color: rgba(255, 255, 255, 0.8);
            background-color: rgba(52, 152, 219, 0.2);
            border-color: rgba(52, 152, 219, 0.2);
        }

            body.dark-mode .btn-primary:focus, body.dark-mode .btn-primary:hover, body.dark-mode .btn-primary:not([href]):focus, body.dark-mode .btn-primary:not([href]):hover, body.dark-mode .btn-primary:not([href]):not([href]):not(:disabled):not(.disabled):focus, body.dark-mode .btn-primary:not([href]):not([href]):not(:disabled):not(.disabled):hover {
                color: white;
                background-color: #3498db;
            }

    .badge-red {
        background: #e74c3c;
    }

    .badge-green {
        background: rgb(0,128,0);
    }
</style>
Loading
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script src="https://code.jquery.com/jquery-migrate-1.4.1.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.2.0/dist/web3.min.js"></script> <script> var mode = getParameterByName("m"); jQuery(window).load(function () { jQuery('#overlayMain').fadeOut(); window.parent.document.getElementById('loadingWriteContractframe').style.display = "none"; window.parent.document.getElementById('overlayMain').style.display = 'none'; if (mode === "dark") { var src = $('body'); src.addClass('dark-mode'); } }); var header = $('#header'); var body = $('#accordion'); var net = getUrlParameter('n'); var address; var ABI = ''; var web3; var contractAddress = getUrlParameter('a'); var myContract; var myContractInstance; var hasInput = false; var api = ''; var isAccount = false; if (net == 'tobalaba') net = 'ecw'; if ((contractAddress !== undefined) || (net !== 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/v3/80f1c00345214da4bdbc4d02f35fb265')); } if (net === 'mainnet') api = '//api.etherscan.io'; else if (net == 'ecw') api = '//api-ewc.etherscan.com'; else api = '//api-' + net + '.etherscan.io'; appendABI(contractAddress, body, 5, false); } function appendABI(contractAddress, body, maxDepth, isProxy) { $.getJSON(api + '/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."); } else { var result = ABI = JSON.parse(data.result); var counter = 0; var maxCounter = 0; $.each(result, function (index, value) { if (value.constant !== false) { if (value.name !== undefined) { if (maxDepth > 0 && value.name.toString() === "implementation" && value.inputs.length === 0) { web3.eth.call({ to: contractAddress, data: "0x5c60da1b" }, function (error, implementationAddress) { if (error) { console.error(error); return; } implementationAddress = web3.utils.toChecksumAddress("0x" + implementationAddress.slice(26)); if (implementationAddress !== "0x") { let implementationSection = NewProxySection(body, implementationAddress); appendABI(implementationAddress, implementationSection, maxDepth - 1, true); } }); } } return; } var value_name = value.name.toString(); if (value_name === "") { return; } counter += 1; var isPayable = value.payable; var counterInput = 0; var maxItemsInput = value.inputs.length; var inputExtr_WithName = ''; if (isPayable) { inputExtr_WithName += '
' + value_name + ' ' + '
'; } var inputId = "input_" + counter; if (isProxy) inputId += "_proxy_" + maxDepth; 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 = '
' + inputName + ' (' + v.type.toString() + ') '; for (d = 0; d < dynamicArray; d++) { var counterInputGroup = "g" + counterInput; if (isProxy) { counterInputGroup += "_proxy_" + maxDepth; } inputTag += ''; } inputTag += '
'; } else { inputTag = GenerateInputTag(inputName, inputId, v.type.toString(), isProxy, maxDepth); } inputExtr_WithName += inputTag; }); } inputExtr_WithName += "Write
"; GenerateRow(value_name, inputExtr_WithName, counter, body); }); $('#footer').show(); } $('.write-btn').addClass('disabled'); var obj = window.parent.document.getElementById('writecontractiframe'); if (obj !== null) parent.resizeIframe(obj, 0); }); } function GenerateInputTag(inputName, inputId, type) { if (inputName !== "") { return '
' + inputName + ' (' + type + ') ' + '
'; } else { return '
' + type + '' + '
'; } } function GenerateRow(fieldName, outputFieldsWithName, counter, body) { if (!hasInput) { hasInput = true; header.append('

Feature Tip: Etherscan Dapp Page - A new front-end interface for any smart contract on Ethereum!

') header.append('

Write Contract Connect to Web3

[Reset]
'); } var output = '
' + '
' + outputFieldsWithName + '
'; body.before(output); } function NewProxySection(body, address) { let section = '

Showing ABI for possible implementation ' + address + '

'; $("#footer").before(section); return $('#impl' + address); } function write0(method, input) { if (isAccount === false) { alert("Please connect to your Web3 provider!"); return; } var functiontoCall = 'myContractInstance.methods.' + 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'); var values = []; if (ctrl[i].value == '' && grp === null) { document.getElementById(input).focus(); 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 }); } var params = encodeParams(inputs); var payableAmountInput = document.getElementById("input_payable_" + method); var payableParam = payableAmountInput && !isNaN(payableAmountInput.value) ? ', { value: web3.toWei(' + Escape(payableAmountInput.value) + ', "ether") }' : ''; try { new Function(functiontoCall + "(" + params + payableParam + ").send({ from:'" + web3.eth.defaultAccount + "'})" + ".on('transactionHash', function(hash) { showTx('', hash, '" + input + "'); })" + ".on('error', function(error) { showTx(error, '', '" + input + "') });")(); } catch (err) { showTx(err.message, '', input); } } function encodeParams(values) { var params = ''; if (values.length === 0) return undefined; for (i = 0; i < values.length; i++) { var param = values[i]; if (param.value !== '') { if (param.grp !== null) { var _grp = values.filter(function (x) { return x.grp == param.grp }); var _grpParam = ''; for (g = 0; g < _grp.length; g++) { param = _grp[g]; if (param.value[0] !== '') { if (g == 0) _grpParam = '[' + toHex(param.type, Escape(param.value[0])); else _grpParam = _grpParam + ',' + toHex(param.type, Escape(param.value[0])); } } _grpParam += ']'; if (i == 0) params += _grpParam; else params += ',' + _grpParam; i += _grp.length - 1; } else { if (i == 0) params = toHex(param.type, Escape(param.value[0])); else params = params + ',' + toHex(param.type, Escape(param.value[0])); } } } return params; } function Escape(val) { if (typeof val === 'string' || val instanceof String) return val.replace(/'/g, "\\u0027"); else return val; } function strip(val) { val = val.replace(/"/g, ''); val = val.replace('[', ''); val = val.replace(']', ''); return val; } function toHex(type, val) { if (Array.isArray(val)) { var param = "["; var i; for (i = 0; i < val.length; i++) { if (i == 0) param += toHex(type, val[i]); else param = param + ',' + toHex(type, val[i]); } param += "]"; return param; } else { if (type.indexOf('bool') !== -1) 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 = 'etherscan.io'; if (net !== 'mainnet' && net == 'tobalaba') _url = "ewc.etherscan.com"; else if (net !== 'mainnet') _url = net + ".etherscan.io" if (msg !== undefined) $('.' + input).html(" View your transaction"); } } async function connectWeb3() { var network = 0; network = await web3.eth.net.getId(); netID = network.toString(); switch (netID) { case "1": network = 'mainnet'; break; case "2": network = 'morden'; break; case "3": network = 'ropsten'; break; case "4": network = 'rinkeby'; break; case "5": network = 'goerli'; break; case "42": network = 'kovan'; break; case "246": network = 'ecw'; break; default: console.log('This is an unknown network.'); } if (network.toLowerCase() !== net.toLowerCase()) { alert("Please connect your Web3 to " + net + ' network'); return false; } else { if (typeof ethereum !== 'undefined') { ethereum.enable().then(function () { getWeb3Accounts(); }); } else { getWeb3Accounts(); } } 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); } function getWeb3Accounts() { 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.utils.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(); $('#connectWeb3').hide(); web3.eth.defaultAccount = accounts[0]; myContractInstance = new web3.eth.Contract(ABI, contractAddress); $('#connector').removeClass("text-danger").addClass("text-success"); $('#connector').attr('title', 'Connected'); $('.write-btn').removeClass("disabled"); } isAccount = true; } } else { alert('Please connect to your Web3 provider!'); } }); } function add0xforAddress(_address) { _address = _address.trim(); if (_address.startsWith("0x") == false && _address.length == 40) { _address = "0x" + _address; } return _address; } function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } } 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); function getParameterByName(name) { var url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); } $(document).ready(function () { $(window).keydown(function (event) { if (event.keyCode == 13) { event.preventDefault(); return false; } }); }); </script>