0

Though I have deployed a new contract but the transactions go to a previously deployed contract in my application. I'm attaching the screenshot of my Remix-ide code and the code for the front end application.I'm newly learning blockchain from this tutorial https://www.youtube.com/watch?v=djRxq7Q7xBk&list=PLsyeobzWxl7oY6tZmnZ5S7yTDxyu4zDW-&index=22 . Please help me out :( enter image description here

These are the codes to my front file

<html>
<body>
    <div>

        <p>Your balance:</p>
        <p id='balance'></p>
        <input type="text" id="amount" placeholder="Enter amount here">
        <button id="deposit">Deposit</button>
        <button id="withdraw">Withdraw</button>

    </div>
    <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.36/dist/web3.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
    <script src="app.js"></script>

</body>

This is my app.js file

var contract;

$(document).ready(function(){
web3=new Web3(web3.currentProvider);

var address='0x74c3847bfb1a0662dcf4c49a88e5001ed076d89c'; //Deployed Contract address
var abi=[
    {
        "constant": false,
        "inputs": [
            {
                "name": "amt",
                "type": "int256"
            }
        ],
        "name": "Deposit",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "constant": false,
        "inputs": [
            {
                "name": "amt",
                "type": "int256"
            }
        ],
        "name": "Withdrawl",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "inputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "constructor"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "GetBalance",
        "outputs": [
            {
                "name": "",
                "type": "int256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }
];

contract=new web3.eth.Contract(abi,address);
contract.methods.GetBalance().call().then(function(bal){
    $('#balance').html(bal);
})

})
//Depositing money $('#deposit').click(function() { var amt=0; amt=parseInt($('#amount').val());

web3.eth.getAccounts().then(function (accounts)
{
    var acc=accounts[0];
    return contract.methods.Deposit(amt).send({ from: acc});                    
}).then(function(tx){
    console.log(tx);
}).catch(function(tx)
{
    console.log(tx);

})

}) //Withdrawing money $('#withdraw').click(function() { var amt=0; amt=parseInt($('#amount').val());

web3.eth.getAccounts().then(function (accounts)
{
    var acc=accounts[0];
    return contract.methods.Withdrawl(amt).send({ from: acc});                    
}).then(function(tx){
    console.log(tx);
}).catch(function(tx)
{
    console.log(tx);

})

})

This my front end application and the screenshot of the metamask popup

I have marked the address of the contract which is not the current address of the contract in my remix-ide.

  • 1
    have you tried clearing the browser cache or force refresh by Ctrl-F5 or something? – hellopeach Aug 15 at 7:02
  • @hellopeach Nope,clearing all kinda cache doesn't ring a bell. Changing the web3 provider to ganache localhost 7545 gives another error : Uncaught (in promise) Error: Returned values aren't valid, did it run Out of Gas? I tried using web3js version from 1.0.0-beta.36 to 1.0.0-beta.35 and it shows a new error : Uncaught (in promise) Error: Couldn't decode from ABI: 0x – chaitanya Aug 15 at 14:06
  • The easiest way to check if your code is not caching the old value is to just right click "view page source" in chrome, then click on your app.js in there and see if the code actually points to the correct address you wanted. – Micky Socaci Aug 16 at 19:54

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.