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

Sending 3 or '3000000000000000' but receiver gets '0.000000000000000003'

April 24, 2021 at 5:53pm

Sending 3 or '3000000000000000' but receiver gets '0.000000000000000003'

April 24, 2021 at 5:53pm
I am trying to send Ether in Ether units i.e. 3 ethers by two different techniques using truffle console: 1)truffle(development)> C1.sendTo(C2.address, 3) and 2)truffle(development)> C1.sendTo(C2.address, 3000000000000000) (where sendTo(...) is a method of myContract1, C1 is the object of myContract1 and C2 is the object of myContract2. But at the receiver end i.e. C2, I am always getting '0.000000000000000003'. Description of myContract1, myContract2 and the migration file is given below: pragma solidity ^0.5.8; contract myContract1 { address owner; constructor() public { owner = msg.sender; } function sendTo(address payable receiver, uint amount) public { receiver.transfer(amount); } function() external payable{ } } myContract2: pragma solidity ^0.5.8; contract myContract2 { //This contract will receive Ether sent by myContract1 address owner; constructor() public { owner = msg.sender; } function() external payable { } } and the migration file is: const myContract1 = artifacts.require("myContract1"); const myContract2 = artifacts.require("myContract2");
module.exports = function(deployer) { deployer.deploy(myContract1); deployer.deploy(MyContract2); }; I am accessing sendTo(..) function of myContract1 through Truffle console. I want to send the amount in Ether through ‘sendTo(..)’ 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.The output is given below, currently C1 has a balance of 7 Ethers: truffle(development)> C1bal = await web3.eth.getBalance(C1.address) undefined truffle(development)> web3.utils.fromWei(C1bal, "ether") '6.993999999999999997' and similarly: truffle(development)> web3.utils.fromWei(C2bal, "ether") '0.000000000000000003' Somebody please guide me. Zulfi.
No messages yet