9

I am getting above error while transferring money from contract wallet to particular user wallet.

My contract code

pragma solidity ^0.4.17;

contract mypool{
    address public manager;
    string poolname;
    uint256 poolEndDate;
    uint256 poolAmount;

    constructor () public {
        manager = msg.sender;
    }

    mapping (address => uint256) public balanceOf;

    /*Payer information*/
    struct Payer {
        string name;
        address player;
        uint256 amount;
    }

    Payer[] public players;
    /*Entering Pool Information*/
    function enterPoolInfo(string name,uint256 endDate, uint256 amount) public {
        poolname = name;
        poolEndDate = endDate;
        poolAmount = amount;
    }
    /*Player information to join pool*/
    function enter(string name,uint256 amount) public payable {

        Payer memory m;
        // players.push(Payer{player:msg.sender,amount:amount});
        m.player = msg.sender;
        m.amount = amount;
        m.name = name;
        players.push(m);
    }

    function getBalance() public view returns (uint) {
        return this.balance;
    }



     function transferd(address _to) payable {
        // if (balanceOf[msg.sender] < _value) throw;           // Check if the sender has enough
        // if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
        // balanceOf[msg.sender] -= _value;                     // Subtract from the sender
        // balanceOf[_to] += _value; 

        uint256 balance = this.balance;
        _to.transfer(balance);                        
    }
}

I am using web3 method to transfer money here is the code

let contract = new web3.eth.Contract(abi, address);
contract.methods.transferd('0x497fe03ba1dabf3b391079e8f69eb178243a736b')
    .send()
    .then(console.log)
    .catch(console.log)

3 Answers 3

13

Please mention the account you're sending this transaction from, like this

contract.methods.transferd('0x497fe03ba1dabf3b391079e8f69eb178243a736b')
    .send({from:accounts[0]})

where accounts[0] holds your current account address

Please read the document here

1
  • if you find the answer helpful then feel free to up-vote :) Sep 27, 2018 at 11:32
0

Your running site is not connected to metamask. That's why this error is popping up. To remove this error, go to your running site and open metamask there, then click on three dots. After that click on connected sites and select option of manually connect to current site then click on next and click on connect. This is how you can remove this error. enter image description here

0

For future reference,

in my case was forgetting to add await while fetching accounts.

const accounts = web3.eth.getAccounts();
 await factory.methods.createCampaign(this.state.minimumContribution).send({ from:accounts[0] });

so adding await to web3.eth.getAccounts(); solved my problem like below .

  const accounts = await web3.eth.getAccounts();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.