menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Truffle Suite

Sweet tools for smart contracts

Channels
Team

Problem with sending value through Solidity function in Truffle

April 16, 2021 at 5:10pm

Problem with sending value through Solidity function in Truffle

April 16, 2021 at 5:10pm
Hi, Please tell me how to send the amount in Ether through the Solidity function. I have got the following contract with transferTo(…) method.
pragma solidity ^0.4.18;
contract A {address owner;
function constructor() { owner = msg.sender;}
function transferTo(address to, uint amount) public {
to.call.value(amount)();
}
function() payable public {}
}
I am accessing transferTo(..) function through Truffle console. I want to send the amount in Ether through ‘transferTo(..)’ method but I think it is accepting the amount in Wei and printing the value in decimal point instead of whole number. Please guide me how to send the value through Truffle console so that it should be in whole number. I invoke the function like:
truffle(development)> await victim.transferTo(receiver.address, 3),
I am talking about the second argument ‘3’. When I am printing its value at the receiver, I am getting the answer in points. I am sending '3' Ether from the transferTo(..) method but I am getting '0.000000000000000003'
truffle(development)> recev = await web3.eth.getBalance(receiver.address)
undefined
truffle(development)> web3.utils.fromWei(recev, "ether")
'0.000000000000000003'
I have tried this also: truffle(development)> const etherValue = web3.utils.fromWei('3000000000000000000', 'ether'); undefined truffle(development)> A.transferTo(VT.address, etherValue )
truffle(development)> VTbal = await web3.eth.getBalance(VT.address) undefined truffle(development)> web3.utils.fromWei(VTbal, "ether") '0.000000000000000003' truffle(development)> { tx:
Some body please guide me how to send Ether through Solidity function in Truffle console..
Zulfi.
No messages yet