通过Java sdk进行交易,这一步的数据如何获取?
以下有一个发送交易的demo可供参考:
String fromWallet = “lat1xxx”;
String fromPrivate = “0x3axxx”;
String toAddress = “lat12xxx”;//接受的地址
//获取nonce
BigInteger nonce = getNonce(fromWallet);
BigInteger gasPrice = new BigInteger(“47000000000000000”);//交易的每个gas的价格,价格越高越容易被执行
BigInteger gasLimit = new BigInteger(“21000”);//gas的数量,太小了不能执行完交易
BigInteger value = new BigInteger(“10000000000000000000000”);//交易的金额
String data = “”;//交易的附加内容,可能是委托的交易,如果是token交易,则是合约的ABI
RawTransaction transaction = RawTransaction.createTransaction(nonce,gasPrice,gasLimit,toAddress,value,data);
byte[] signTransaction = TransactionEncoder.signMessage(transaction,chainId,Credentials.create(fromPrivate));
//签完名就将签名数据转换成16进制
String hexSignedTransaction = Numeric.toHexString(signTransaction);
PlatonSendTransaction response = web3j.platonSendRawTransaction(hexSignedTransaction).send();