1

How do I connect my web3 to ropsten network. I know how to pass the url of ropsten netwrok in web3 instance in my script tag but when i try to to console.log(web3.eth.defaultaccount) it gives me undefined in console and its not making calls to my contract which is already deployed on ropsten. Can anybody please help?

<!DOCTYPE html>
<html>
 <head>
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Lets Bid</title>
 <script src="node_modules/web3/dist/web3.min.js"></script>
</head>
<body>
 <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

    <center> <h1 style="background-color:rgb(25, 171, 255);"><b>BIDDING WEBSITE</b></h1>   
        <img src="14142904-GladdenPrivateIsland_cropped_1584x780.jpg"width="400" > 
        <h2><strong>PRICE:600 $ </strong></h2><br>    
        <form>
                First name:<br>
                <input type="text" id="firstname"><br>
                Bid:<br>
                <input type="text" id="bid"><br><br>
                <button id="sub" onclick="getuserdata();">Submit</button><br><br><br>
                <h2 id="getbid">Highest Bid</h2>
                <button id="Sh" type="button" onclick="hibid(); return false;">Show</button>
              </form> 
              </center>  
         <script>
            if(typeof web3!=='undefined')
            {
              web3=new Web3(web3.currentProvider);
            }else{
                web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/0db053799f0e48e99357b6dce022b1e7"));
            }
       // web3.eth.defaultAccount=web3.eth.accounts[0];

            var Biddingcontract=web3.eth.contract([
    {
        "constant": false,
        "inputs": [
            {
                "name": "_name",
                "type": "string"
            },
            {
                "name": "_bid",
                "type": "uint256"
            }
        ],
        "name": "addusers",
        "outputs": [
            {
                "name": "",
                "type": "bool"
            }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "GethighestBidder",
        "outputs": [
            {
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "Gettotalbidders",
        "outputs": [
            {
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }])


      var BiddingAddress=Biddingcontract.at('0xa19303f703a17e6455bd6536a1abf2a0f3d789d0');
       console.log(BiddingAddress);
       console.log(web3.eth.defaultAccount);
           function getuserdata()
               {
                 var nameholder=$('#firstname').val();
                 var bidholder= $('#bid').val();   
                 BiddingAddress.addusers(nameholder,bidholder);//,{from: web3.eth.accounts[0], gas:3000000});
                 alert("Successfull");
               }   
               function hibid () 
               {
                 var holder=  BiddingAddress.GethighestBidder();
                 document.getElementById("getbid").innerHTML=holder;
               }
               </script>         
</body>
</html>

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.