简体   繁体   中英

How to transfer on truffle develop

I made this contract:

pragma solidity ^0.4.25;

contract MyTransfer {
    address owner;
    uint data;
    uint private amount;
    string greeting = "Hello World";
    constructor() public {
        owner = msg.sender;
    }
    function greet () constant public returns (string) {
        return greeting;
    }
    function deposit() public payable {
        amount += msg.value;
    }
    function withdraw() public {
        msg.sender.transfer(amount);
    }
    function kill () public {
        require(owner == msg.sender);
        selfdestruct(owner);
    }
}

Compile and deploy successfully finished.

Then on truffle develop console.

mt = MyTransfer.at(MyTransfer.address);

>mt.greet();

works

>mt.deposit(1);

Error: Invalid number of arguments to Solidity function

How can I make transfer on truffle console?

It is not working because your deposit() function is not waiting for any params. You need to send some value with your transaction in order for it to work. Try this:

mt.deposit({value: 'the amount of ether you want to send'});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM