我是 web3 和以太坊区块链的新手。我尝试使用以下代码广播交易,但它总是给我一个无效的发件人错误。示例代码如下所示。
const Tx = require('ethereumjs-tx').Transaction;
const Web3 = require('web3');
var url = 'https://ropsten.infura.io/v3/XXX';
const web3 = new Web3(new Web3.providers.HttpProvider(url));
const account1 = '0xaB7BXXX';
web3.eth.defaultAccount = account1;
const privatekey1 = Buffer.from('fee069363aXXX','hex');
web3.eth.getTransactionCount(account1, (err, txCount) => {
data = "0xXXX";
const txObject = {
nonce: web3.utils.toHex(txCount),
gasLimit: web3.utils.toHex(200000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
data: data
}
const tx = new Tx(txObject)
tx.sign(privatekey1)
const serializedTx = tx.serialize()
const raw = '0x' + serializedTx.toString('hex')
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
console.log('err:', err, 'txHash:', txHash)
}) …Run Code Online (Sandbox Code Playgroud) 我正在使用 java 的 socketio 和 netty,而且我对它们都是新手。
\n我的客户端代码如下所示。
\n<!DOCTYPE html>\n<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">\n<head>\n <title >webSocket test</title>\n <script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>\n <script src="https://cdn.socket.io/3.1.3/socket.io.min.js" integrity="sha384-cPwlPLvBTa3sKAgddT6krw0cJat7egBga3DJepJyrLl4Q9/5WLra3rrnMcyTyOnh" crossorigin="anonymous"></script>\n < !-- New Bootstrap core CSS file-->\n <!-- Optional Bootstrap theme file (generally not necessary to import) -->\n <!- -jQuery file. Be sure to introduce before bootstrap.min.js -->\n\n <!-- The latest Bootstrap core JavaScript file-->\n <script type=" text/javascript">\n $(function(){\n /**\n * The socket.emit("event name", "parameter data") method of the\n front-end js is used when triggering the back-end …Run Code Online (Sandbox Code Playgroud)