如何在 truffle develop 上迁移

How to transfer on truffle develop

我签了这个合同:

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);
    }
}

编译部署成功。

然后在 truffle 开发控制台上。

mt = MyTransfer.at(MyTransfer.address);

>mt.greet();

有效

>mt.deposit(1);

Error: Invalid number of arguments to Solidity function

如何在 truffle console 上进行传输?

它不起作用,因为您的 deposit() 函数没有等待任何参数。您需要通过交易发送一些价值才能使其正常工作。试试这个:

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