我有一个制造代币并将其转移的工作系统,具体如下-
> addrtoken.balanceOf(eth.accounts[0])
33333250
> addrtoken.balanceOf(eth.accounts[1])
50我想测试buyTokens函数。这个函数使用msg.value,我不知道如何测试它。这是下面的内容。有没有办法把msg.value发送到geth?
// fallback function to buy tokens
function () payable {
buyTokens(msg.sender);
}
/**
* Low level token purchse function
* @param beneficiary will recieve the tokens.
*/
function buyTokens(address beneficiary) payable whenNotPaused {
require(beneficiary != 0x0);
require(validPurchase());
uint256 weiAmount = msg.value;
// update weiRaised
weiRaised = weiRaised.add(weiAmount);
// compute amount of tokens created
uint256 tokens = weiAmount.mul(rate);
token.mint(beneficiary, tokens);
TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);
forwardFunds();
}发布于 2017-08-22 11:50:53
回退函数调用的buyToken函数。因此,必须触发回退函数,在geth控制台上如下所示:
eth.sendTransaction({from:eth.coinbase,to:addrtoken.address,value:10})关于回退功能,请阅读此退却
希望能帮上忙~
发布于 2017-08-22 11:43:58
尝尝这个,
MyToken.deployed().then(function(instance) { return instance.buyToken('0x0ab768ac22111fdd177085238a7b51f6270497d0','0x38a1f9f495fdef18f18073eef329945316a5d281',100);}).then(console.log());https://ethereum.stackexchange.com/questions/24901
复制相似问题