1

I wanna achieve smart contract to send ETH back to the sender on some conditions:

function() public payable {
    msg.sender.transfer(msg.value);
}

I am passing gasLimit equal to 4700000:

web3.eth.sendTransaction({from: wallet, to: contract.address, value: ether(2), gasLimit: 4700000});

And still see error when running on testrpc:

Error: VM Exception while processing transaction: out of gas

Sending ETH to other smart contract usually works fine. What's wrong with instant refund?

2

You've set the gasLimit not the gas. I think what you meant to send was:

web3.eth.sendTransaction({from: wallet, to: contract.address, value: ether(2), gas: 4700000});

Your Answer

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

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