web3j发交易和查询余额
Posted 大自然熊猫
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web3j发交易和查询余额相关的知识,希望对你有一定的参考价值。
var Web3 = require(‘web3‘); var fs = require(‘fs‘); var Tx = require(‘ethereumjs-tx‘); var store = require(‘./data.js‘)
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8866"));
//发布合约得到的合约地址
var contract_addr ="";
var data ="";
//编译合约源码得到abi和data let abi= JSON.parse(fs.readFileSync("./abi.txt")); var USDT = new web3.eth.Contract(abi,contract_addr);
//发布合约 function deploy(){ web3.eth.getTransactionCount(add_form,"pending",function(err,nonce){ if(err){ console.log("获取nonce出错",err); return; } console.log("获得nonce:",nonce); var rawTx = { nonce:web3.utils.toHex(nonce), from: add_form, gasLimit: web3.utils.toHex(21000), gasPrice: web3.utils.toHex(web3.utils.toWei("15", "gwei")), data:data
} var tx = new Tx(rawTx); tx.sign(privateKey); var serializedTx = tx.serialize(); web3.eth.sendSignedTransaction(‘0x‘ + serializedTx.toString(‘hex‘),function(err, hash){ if (!err) { console.log(hash); } else { console.error(err); } }); }); } //发送合约交易 function contractTransfer(amount,targetAddr){ var transfer_code = USDT.methods.transfer(targetAddr, web3.utils.toWei(amount,‘mwei‘)).encodeABI(); web3.eth.getTransactionCount(add_form,"pending",function(err,nonce){ if(err){ console.log("获取nonce出错",err); return; } console.log("获得nonce:",nonce); var transfer_rawTx = { nonce:web3.utils.toHex(nonce), from: add_form, to: contract_addr, value: "0x0", gasLimit: web3.utils.toHex(60000), gasPrice: web3.utils.toHex(web3.utils.toWei("15", "gwei")), data:transfer_code } var tx = new Tx(transfer_rawTx); tx.sign(privateKey); var serializedTx = tx.serialize(); console.log("开始发送交易...") web3.eth.sendSignedTransaction(‘0x‘ + serializedTx.toString(‘hex‘),function(err, hash){ if (!err) { console.log("发送成功,等待回执:",hash); } else { console.error("发送失败",err); } }).then(function(data) { console.log("交易结果 data:"+JSON.stringify(data)); }); }) } //查询交易状态 function getTransactionReceipt(hash){ var receipt = web3.eth.getTransactionReceipt(hash).then(console.log); console.log("交易信息:",receipt); } //根据交易hash查询交易信息 function getTransactionHash(hash){ var result = web3.eth.getTransaction(hash).then(console.log); console.log("交易信息:",result); } //查询代币余额 function balanceOf(addr){ USDT.methods.balanceOf(addr).call(function(error, result){ if(!error) { console.log(addr,":",web3.utils.fromWei(result, ‘mwei‘)) } else { console.log(addr,":",error); } }); } //查询主币余额
function balance(addr){ web3.eth.getBalance(addr).then(console.log); } //发主币交易 function mainTransfer(item){ web3.eth.getTransactionCount(item.from,function(error,nonce){ let tx = new Tx({ nonce : web3.utils.toHex(nonce), to: item.to, value: web3.utils.toHex(web3.utils.toWei(item.val, "ether") ), gasLimit: web3.utils.toHex(600000), gasPrice: web3.utils.toHex(web3.utils.toWei("15", "gwei")), data:data
}); let privateKey = Buffer.from(item.key, ‘hex‘) tx.sign(privateKey); let serializedTx = tx.serialize(); web3.eth.sendSignedTransaction(‘0x‘ + serializedTx.toString(‘hex‘),function(err, hash){ console.log("交易结果预览:{error:"+err+",hash:"+hash+"}"); }).then(function(data) { console.log("交易结果 data:"+JSON.stringify(data)); }); }) }
var Web3 = require(‘web3‘);var fs = require(‘fs‘);var Tx = require(‘ethereumjs-tx‘);var store = require(‘./data.js‘)
var web3 = new Web3(new Web3.providers.HttpProvider("http://47.244.5.41:8866"));var contract_addr = "0x219fe3C10158c410B03833793a86E7c51B86f09A";
let abi= JSON.parse(fs.readFileSync("./abi.txt"));var USDT = new web3.eth.Contract(abi,contract_addr);
var add_form = "0xbe77356f55a762ccec56441efff7c7aefe32b67a"; var privateKey = Buffer.from("c709f97493fd44e4988f9a9054ebd668bef04de6465576da83d14002600b1f8e", ‘hex‘); //contractTransfer("99","0x8b5f07dde19915dff057a97afd07c8bd2e1087c3");
var adds = [{from:‘0x212615d3048463dc2d84871bfcaf7705fddb958f‘,key:‘6eaf720227d7ca5cf17f804c3a8a55631b527d297ed17710b90b2c42474c3b3f‘,to:‘0x8b5f07dde19915dff057a97afd07c8bd2e1087c3‘,val:‘1.5‘}]mainTransfer(adds[0]);
//balanceOf("0x8b5f07dde19915dff057a97afd07c8bd2e1087c3"); //balance("0x212615d3048463dc2d84871bfcaf7705fddb958f")
//web3.eth.getBlock(139547).then(console.log);
//getTransactionReceipt("0x7eded19bc047b95e0eeb4fb72a26ef98f1eaa43b5369b8376f0b8a02a5005575")//getTransactionHash("0x2d404d0f5c73cc17e88ffd67120459a2125f9f39dc3672119f097ed717119260")//Convert.toWei(EthConstant.GAS_PRICE, Convert.Unit.GWEI).toBigInteger()
//发布合约function deploy(){web3.eth.getTransactionCount(add_form,"pending",function(err,nonce){if(err){console.log("获取nonce出错",err);return;}console.log("获得nonce:",nonce);var rawTx = { nonce:web3.utils.toHex(nonce),from: add_form,gasLimit: web3.utils.toHex(21000),gasPrice: web3.utils.toHex(web3.utils.toWei("15", "gwei")),data:"0x608060405234801561001057600080fd5b5060126004819055506040805190810160405280600381526020017f59414b000000000000000000000000000000000000000000000000000000000081525060059080519060200190610064929190610178565b506040805190810160405280600381526020017f59414b0000000000000000000000000000000000000000000000000000000000815250600390805190602001906100b0929190610178565b5033600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600454600a0a63fa56ea0002600181905550600154600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060008060006101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555061021d565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101b957805160ff19168380011785556101e7565b828001600101855582156101e7579182015b828111156101e65782518255916020019190600101906101cb565b5b5090506101f491906101f8565b5090565b61021a91905b808211156102165760008160009055506001016101fe565b5090565b90565b610cf78061022c6000396000f3006080604052600436106100c5576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100ca578063095ea7b31461015a57806318160ddd146101a757806323b872dd146101d2578063275791521461023f578063313ce567146102565780634bf365df1461028157806362bbadf8146102b057806370a08231146102ef5780638da5cb5b1461034657806395d89b411461039d578063a9059cbb1461042d578063dd62ed3e1461047a575b600080fd5b3480156100d657600080fd5b506100df6104f1565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011f578082015181840152602081019050610104565b50505050905090810190601f16801561014c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561016657600080fd5b506101a5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061058f565b005b3480156101b357600080fd5b506101bc610679565b6040518082815260200191505060405180910390f35b3480156101de57600080fd5b5061023d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061067f565b005b34801561024b57600080fd5b506102546108ef565b005b34801561026257600080fd5b5061026b61098f565b6040518082815260200191505060405180910390f35b34801561028d57600080fd5b50610296610995565b604051808215151515815260200191505060405180910390f35b3480156102bc57600080fd5b506102c56109a8565b604051808267ffffffffffffffff1667ffffffffffffffff16815260200191505060405180910390f35b3480156102fb57600080fd5b50610330600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109c5565b6040518082815260200191505060405180910390f35b34801561035257600080fd5b5061035b610a0e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156103a957600080fd5b506103b2610a34565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103f25780820151818401526020810190506103d7565b50505050905090810190601f16801561041f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561043957600080fd5b50610478600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ad2565b005b34801561048657600080fd5b506104db600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c44565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105875780601f1061055c57610100808354040283529160200191610587565b820191906000526020600020905b81548152906001019060200180831161056a57829003601f168201915b505050505081565b80600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a35050565b60015481565b80600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015801561074a575080600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156107565750600081115b151561076157600080fd5b80600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555080600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555080600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561094b57600080fd5b60016000808282829054906101000a900467ffffffffffffffff160192506101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550565b60045481565b600260009054906101000a900460ff1681565b60008060009054906101000a900467ffffffffffffffff16905090565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610aca5780601f10610a9f57610100808354040283529160200191610aca565b820191906000526020600020905b815481529060010190602001808311610aad57829003601f168201915b505050505081565b6040600481016000369050141515610ae657fe5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b355750600082115b1515610b4057600080fd5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3505050565b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820790202dd97b91dc95b3f9b32a5df4adfc530954281e1da5e89a77712fd3bf0cc0029"}var tx = new Tx(rawTx);tx.sign(privateKey);var serializedTx = tx.serialize();web3.eth.sendSignedTransaction(‘0x‘ + serializedTx.toString(‘hex‘),function(err, hash){if (!err) { console.log(hash); } else { console.error(err); }});});}
//发送合约交易function contractTransfer(amount,targetAddr){var transfer_code = USDT.methods.transfer(targetAddr, web3.utils.toWei(amount,‘mwei‘)).encodeABI();web3.eth.getTransactionCount(add_form,"pending",function(err,nonce){if(err){console.log("获取nonce出错",err);return;}console.log("获得nonce:",nonce);var transfer_rawTx = {nonce:web3.utils.toHex(nonce),from: add_form,to: contract_addr,value: "0x0",gasLimit: web3.utils.toHex(60000),gasPrice: web3.utils.toHex(web3.utils.toWei("15", "gwei")),data:transfer_code}var tx = new Tx(transfer_rawTx); tx.sign(privateKey); var serializedTx = tx.serialize(); console.log("开始发送交易...") web3.eth.sendSignedTransaction(‘0x‘ + serializedTx.toString(‘hex‘),function(err, hash){if (!err) { console.log("发送成功,等待回执:",hash); } else { console.error("发送失败",err); }}).then(function(data) {console.log("交易结果 data:"+JSON.stringify(data));});})}
//查询交易状态function getTransactionReceipt(hash){var receipt = web3.eth.getTransactionReceipt(hash).then(console.log);console.log("交易信息:",receipt);}
//根据交易hash查询交易信息function getTransactionHash(hash){var result = web3.eth.getTransaction(hash).then(console.log);console.log("交易信息:",result);}
//查询代币余额function balanceOf(addr){USDT.methods.balanceOf(addr).call(function(error, result){ if(!error) {console.log(addr,":",web3.utils.fromWei(result, ‘mwei‘)) } else { console.log(addr,":",error); }});}
//查询主币余额function balance(addr){web3.eth.getBalance(addr).then(console.log);}
//发主币交易function mainTransfer(item){web3.eth.getTransactionCount(item.from,function(error,nonce){let tx = new Tx({nonce : web3.utils.toHex(nonce),to: item.to,value: web3.utils.toHex(web3.utils.toWei(item.val, "ether") ),gasLimit: web3.utils.toHex(600000),gasPrice: web3.utils.toHex(web3.utils.toWei("15", "gwei")),data:"0x608060405234801561001057600080fd5b5060126004819055506040805190810160405280600381526020017f59414b000000000000000000000000000000000000000000000000000000000081525060059080519060200190610064929190610178565b506040805190810160405280600381526020017f59414b0000000000000000000000000000000000000000000000000000000000815250600390805190602001906100b0929190610178565b5033600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600454600a0a63fa56ea0002600181905550600154600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060008060006101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555061021d565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101b957805160ff19168380011785556101e7565b828001600101855582156101e7579182015b828111156101e65782518255916020019190600101906101cb565b5b5090506101f491906101f8565b5090565b61021a91905b808211156102165760008160009055506001016101fe565b5090565b90565b610cf78061022c6000396000f3006080604052600436106100c5576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100ca578063095ea7b31461015a57806318160ddd146101a757806323b872dd146101d2578063275791521461023f578063313ce567146102565780634bf365df1461028157806362bbadf8146102b057806370a08231146102ef5780638da5cb5b1461034657806395d89b411461039d578063a9059cbb1461042d578063dd62ed3e1461047a575b600080fd5b3480156100d657600080fd5b506100df6104f1565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561011f578082015181840152602081019050610104565b50505050905090810190601f16801561014c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561016657600080fd5b506101a5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061058f565b005b3480156101b357600080fd5b506101bc610679565b6040518082815260200191505060405180910390f35b3480156101de57600080fd5b5061023d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061067f565b005b34801561024b57600080fd5b506102546108ef565b005b34801561026257600080fd5b5061026b61098f565b6040518082815260200191505060405180910390f35b34801561028d57600080fd5b50610296610995565b604051808215151515815260200191505060405180910390f35b3480156102bc57600080fd5b506102c56109a8565b604051808267ffffffffffffffff1667ffffffffffffffff16815260200191505060405180910390f35b3480156102fb57600080fd5b50610330600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109c5565b6040518082815260200191505060405180910390f35b34801561035257600080fd5b5061035b610a0e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156103a957600080fd5b506103b2610a34565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103f25780820151818401526020810190506103d7565b50505050905090810190601f16801561041f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561043957600080fd5b50610478600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ad2565b005b34801561048657600080fd5b506104db600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c44565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105875780601f1061055c57610100808354040283529160200191610587565b820191906000526020600020905b81548152906001019060200180831161056a57829003601f168201915b505050505081565b80600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a35050565b60015481565b80600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015801561074a575080600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156107565750600081115b151561076157600080fd5b80600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555080600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555080600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561094b57600080fd5b60016000808282829054906101000a900467ffffffffffffffff160192506101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550565b60045481565b600260009054906101000a900460ff1681565b60008060009054906101000a900467ffffffffffffffff16905090565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610aca5780601f10610a9f57610100808354040283529160200191610aca565b820191906000526020600020905b815481529060010190602001808311610aad57829003601f168201915b505050505081565b6040600481016000369050141515610ae657fe5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b355750600082115b1515610b4057600080fd5b81600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3505050565b6000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820790202dd97b91dc95b3f9b32a5df4adfc530954281e1da5e89a77712fd3bf0cc0029"});let privateKey = Buffer.from(item.key, ‘hex‘)tx.sign(privateKey);let serializedTx = tx.serialize();web3.eth.sendSignedTransaction(‘0x‘ + serializedTx.toString(‘hex‘),function(err, hash){console.log("交易结果预览:{error:"+err+",hash:"+hash+"}");}).then(function(data) {console.log("交易结果 data:"+JSON.stringify(data));});})}
以上是关于web3j发交易和查询余额的主要内容,如果未能解决你的问题,请参考以下文章