Truffle 向合约发送以太
有时,可能想直接将以太发送到合约,或者想触发合约的回退函数。可以使用下面的方法:
通过
instance.sendTransaction()将交易直接发送到合约,这个函数与其他的合约抽象函数一样,具有promise机制。
instance.sendTransaction({...}).then(function(result) {
// 处理交易结果
});
或者通过
instance.send()函数直接发送以太:
instance.send(web3.utils.toWei(1, "ether")).then(function(result) {
// 处理交易结果
});