在我的js文件中,我将发送交易称为智能合约,那么值之间有什么区别:
instance.multiply.sendTransaction(val,{ from: accounts[0], gas : 300000}
和instance.multiply.sendTransaction({ from: accounts[0], gas : 30000, value : val}
,
我将第一个传递给函数作为参数,而第二个可以通过msg.value
进行访问?
答案 0 :(得分:0)
web3.eth.sendTransaction的正确语法
web3.eth.sendTransaction(transactionObject [, callback])
第二个可以正常工作,instance.multiply.sendTransaction({ from: accounts[0], gas : 30000, value : val},
并且应该。
sendTransaction的格式为sendTransaction({from: eth.accounts[0], data: code, gas: 100000})
。
from:
字符串-发送帐户的地址。使用
web3.eth.defaultAccount属性(如果未指定)。to:
字符串-(可选)消息的目标地址,
对于合同创建交易未定义。 value:
Number | String | BigNumber-(可选)已传输的值
在魏的交易中,如果是
合同创建交易。
gas:
Number | String | BigNumber-(可选,默认值:
待确定)用于交易的天然气量
(未使用的气体将退还)。
data
:字符串-(可选)包含
消息的相关数据,或者
合同创建交易,初始化代码。有关更多信息,请参见:https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction
答案 1 :(得分:0)
在您的第一个代码段中,您将val
作为参数传递给函数。
在第二个代码段中,您没有传递任何参数,但在事务中发送了val
wei。是的,合同可以通过查看msg.value
来查看发送了多少wei,但重要的是还有以太坊的转移。 (10 ** 18 wei == 1醚。)
所以两者之间的主要区别是: