在我的js文件中,我将智能合约的发送事务调用,因此值之间有什么区别:
instance.multiply.sendTransaction(val,{ from: accounts[0], gas : 300000}
和instance.multiply.sendTransaction({ from: accounts[0], gas : 30000, value : val}
,
我将第一个作为参数传递给函数,第二个函数只能通过msg.value
在函数中访问?
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:
String - 发送帐户的地址。如果未指定,则使用web3.eth.defaultAccount属性。to:
String - (可选)消息的目标地址,未定义为合同创建事务。value:
Number | String | BigNumber - (可选)为Wei中的交易转移的价值,如果是合约创建交易,也是禀赋。gas:
Number | String | BigNumber - (可选,默认:待定)用于交易的天然气量(未使用的天然气被退还)。data
:String - (可选)包含消息的关联数据的字节字符串,或者在合同创建事务的情况下,是初始化代码。欲了解更多信息,请参阅:https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction
在您的第一个代码段中,您将val
作为参数传递给函数。
在第二个代码片段中,您没有传递任何参数,但是您在事务中发送了val
wei。是的,合同,通过查看msg.value
可以看出发送了多少wei,但重要的是还有一个以太的转移。 (10 ** 18 wei == 1 ether。)
所以两者之间的主要区别是: