简体   繁体   English

如何在以太坊交易中发送消息

[英]How to send messages on a transaction in the Ethereum

I want to send a message on a transaction. 我想发送有关交易的消息。 Here is my codes: 这是我的代码:

_data = web3.toHex('xxxx');

instance.function_name(param1, param2, param3, param4, {value: web3.toWei(_price, 'ether'), from: web3.eth.accounts[0], data:_data}).then(...);

The transaction is processed successfully, But the input data message is not the _data value in the etherscan.io 该交易成功处理,但是输入数据消息不是_data在值etherscan.io

can anybody help me? 有谁能够帮助我? Thank you. 谢谢。

The data field in the transaction object is used when deploying a contract or when using the general sendTransaction or sendRawTransaction methods. 部署合同或使用常规sendTransactionsendRawTransaction方法时,将使用事务对象中的data字段。 If you are using a contract instance, the data field is ignored. 如果使用合同实例,则data字段将被忽略。

From the Solidity docs : Solidity文档

Object - (optional) The (previous) last parameter can be a transaction object, see web3.eth.sendTransaction parameter 1 for more. 对象-(可选)(上一个)最后一个参数可以是事务对象,有关更多信息,请参见web3.eth.sendTransaction参数1。 Note: data and to properties will not be taken into account. 注意:不会考虑数据和属性。

If you want to send the data manually, use sendTransaction . 如果要手动发送数据,请使用sendTransaction

The information shown in Etherscan is the decoded data from the signed transaction describing the function call made. Etherscan中显示的信息是来自已签名事务的解码数据,描述了进行的函数调用。 It is not free form user data (if that's what you're trying to insert). 它不是自由格式的用户数据(如果这是您要插入的内容)。 The first 32 bits of the data are the function signature and each 256 bit block afterwards are the parameters. 数据的前32位是功能签名,其后的每个256位块是参数。

See this source for more in-depth information. 有关更多深入信息,请参见此资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM