0 votes
1 view
in Blockchain by (12.2k points)

I'm trying to make a simple paywall which uses Etherscan API to retrieve transactions from an address (currently set to my wallet on the rinkby testnetwork) and gather all the "from" addresses (the addresses of all people who have sent money to the address in a very basic way).I managed to create a string of all the senders. Next part I need to check this list of addresses against an address entered on the webpage - if the address entered matches an address on the string of senders addresses var x - the pay wall is lifted.

This is where I'm stuck.

Both input from the input box and the x variable are stings, as shown in the console. However I cant get an input value to be matched to x.

I tried matching and using indexOf, which will work if you have entered the address manually as part of the code (shown in code) but it won't work with a value from the input box. I tried a similar thing with indexOf, same problem.

Another issue I run into if I can get this to work is that i need there to be an exact match for a full address only, as partial matches can still be found in x with the methods I've tried.

I essentially need the sender address to act as a password/key to access whatever is behind the paywall.

I'm sure there are lots of better ways of doing this, please help if you can

<?php 

$url = "http://api-rinkeby.etherscan.io/api?module=account&action=txlist&address=0x445b5f277D463122a2Aaeac8B77d8f60865156Dc&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken";

$fgc = json_decode(file_get_contents($url), true);

$fgc2 = $fgc["result"];

?>

<html>

all senders

<div id="demo"> </div>

matched in all senders list

<div id="demo2"></div>

<input type="text" id="ethadd" onChange="ethConvert()"; onKeyUp="ethConvert()"; value="enter address";  > enter address to check if payment has been sent

<script>

var myObj, i, x = "", lenght, allSenders; 

var amount = document.getElementById("ethadd").value

var amount2 = toString(amount);

myObj = <?php echo json_encode($fgc2);?>;

for (i in myObj) {

    x += myObj[i].from + "<br>" ;

}

//both iput from the iput box and the x variable are stings however I cant get an input value to be matched to x

console.log(typeof x);

console.log(typeof amount);

var n = x.indexOf(amount);

//tried using this to match an address put in the input box to part of the string - it works if you have enter the address

//manually like this but wont work with a value fromt the input box tried a similar thing with indexOf, same problem - wont work with

//anything from the input box 

var string = x;

var expr = /0x445b5f277d463122a2aaeac8b77d8f60865156dc/

document.getElementById("demo2").innerHTML = string.match(expr);

document.getElementById("demo").innerHTML = x;

</script>

</html>

1 Answer

0 votes
by (28.6k points)

Hi, please refer to the following code ,please note that it is not secure so put anything important on it

<?php
    $apiKey       = '';
    $url          = "http://api-rinkeby.etherscan.io/api?module=account&action=txlist&address=0x445b5f277D463122a2Aaeac8B77d8f60865156Dc&startblock=0&endblock=99999999&sort=asc&apikey={$apiKey}";
    $transactions = json_decode(file_get_contents($url), true);
    $addresses    = [];

    if (isset($transactions['result'])) {
        foreach ($transactions['result'] as $transaction) {
            $addresses[] = $transaction['from'];
        }
        // in php5.5+, this foreach could be replaced with
        // $addresses = array_column($transactions['result'], 'from');
    }
?>
<html>
    enter address to check if payment has been sent

    <input type="text" id="eth_address" onchange="checkAddress()" value="enter address" />
    <!-- you had some markup mistakes on this input, specifically the ; chars -->

    <script>
        var addresses = <?php echo json_encode($addresses); ?>;

        function isValid() {
            return addresses.indexOf(document.getElementById('eth_address').value) > -1;
        }

        function checkAddress() {
            if (isValid()) {
                alert('lift paywall');
            }
        }
    </script>
</html>

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...