【发布时间】:2020-07-03 13:53:33
【问题描述】:
我的函数一直返回一个事务哈希,但它应该返回一个 uint。我将其称为控制台 sale.priceOfEther() 中的一个函数。我正在使用solidity 0.5.0 和ganache。
function priceOfEther() public view returns (uint256){
uint256 maxTokenPrice = WEI_DECIMALS.div(100).mul(7); //max price $0.07 USD per token multiplied by wei early to avoid truncation by division.
uint256 minTokenPrice = WEI_DECIMALS.div(1000).mul(7); //min price $0.007 USD per token multiplied by wei early to avoid truncation by division.
uint256 minWeiPerToken = minTokenPrice.div(ethUSD);
uint256 maxWeiPerToken = maxTokenPrice.div(ethUSD);
uint256 increments = (maxWeiPerToken.sub(minWeiPerToken)).div(AVG_NUM_INVESTORS);
price = minWeiPerToken.add(increments.mul(count));
if (price > maxWeiPerToken) {
price = maxWeiPerToken;
}
assert(price != 0);
return price;
}
这是 truffle 控制台中返回的内容
{ tx: '0x8c3c2b4979117f380a7f6d39fd6f46e3566436ada25b5048ecaaef40743f5586',
receipt:
{ transactionHash: '0x8c3c2b4979117f380a7f6d39fd6f46e3566436ada25b5048ecaaef40743f5586',
transactionIndex: 0,
blockHash: '0xc3410bdede3bb7afe8889065dc8089a48d7e1285c63e7c43a205bd33d7cc0884',
blockNumber: 11,
from: '0x3f32e6ca9e7f433d0f5dea6b1024d3b0768e2dbf',
to: '0x6bab62d945dfe3c862caf9a3b59c6c435f3de1d4',
gasUsed: 50007,
cumulativeGasUsed: 50007,
contractAddress: null,
logs: [],
status: true,
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
rawLogs: [] },
logs: [] }
【问题讨论】:
标签: javascript solidity