cita-java-sdk中的Transaction问题

Transaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)中的version,chainId,value是随便取值的吗?不包含Token的合约,value有什么作用?

而且 0.23.0版本的jar包中,chainId类型是BigInteger,文档里还是int

  • Version 指的是 CITA 的协议版本
  • chainId 指的是当前链的 id, 你可以用 getMetaData 接口获得;
  • value 指的是本次交易的转帐金额。

都不是可以随例取值。

谢谢你的反馈,我们会尽快更新文档的

文档已更新 https://github.com/cryptape/cita-sdk-java/blob/develop/docs/index.md。

如果还有其他问题,后续可以再讨论,谢谢。

好的,辛苦:grinning:

对于部署合约或其非转账交易,value取0就行?

是的。如果你写非 0 , 就会有一笔 value 从你的帐户转到合约帐户。

AppSendTransaction result = service.appSendRawTransaction(rawTx).send();
发送交易后,result是空,会是什么原因?

@DuanYangyang, 你晓得这是什么问题吗?

result 有错误信息吗?还是什么信息都没有?能贴一下返回值吗?谢谢

result is empty.
result.getSendTransactionResult() is null

这是我的代码
public static void main(String[] args) {
long currentHeight = 0L;
long validUntilBlock = currentHeight + 80;
Random random = new Random(System.currentTimeMillis());
String nonce = String.valueOf(Math.abs(random.nextLong()));
long quota = 1000000;
Transaction tx = Transaction.createContractTransaction(nonce, quota, validUntilBlock,1, BigInteger.ZERO,“0”, “608060405234801561001057600080fd5b50610f7c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80632b94086414610046578063b24a4e52146103f4578063fb3368c914610528575b600080fd5b6103f2600480360360c081101561005c57600080fd5b810190808035906020019064010000000081111561007957600080fd5b82018360208201111561008b57600080fd5b803590602001918460018302840111640100000000831117156100ad57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561011057600080fd5b82018360208201111561012257600080fd5b8035906020019184600183028401116401000000008311171561014457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156101a757600080fd5b8201836020820111156101b957600080fd5b803590602001918460018302840111640100000000831117156101db57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561023e57600080fd5b82018360208201111561025057600080fd5b8035906020019184600183028401116401000000008311171561027257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156102d557600080fd5b8201836020820111156102e757600080fd5b8035906020019184600183028401116401000000008311171561030957600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561036c57600080fd5b82018360208201111561037e57600080fd5b803590602001918460018302840111640100000000831117156103a057600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506108d6565b005b6104ad6004803603602081101561040a57600080fd5b810190808035906020019064010000000081111561042757600080fd5b82018360208201111561043957600080fd5b8035906020019184600183028401116401000000008311171561045b57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610a7c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104ed5780820151818401526020810190506104d2565b50505050905090810190601f16801561051a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6108d4600480360360c081101561053e57600080fd5b810190808035906020019064010000000081111561055b57600080fd5b82018360208201111561056d57600080fd5b8035906020019184600183028401116401000000008311171561058f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156105f257600080fd5b82018360208201111561060457600080fd5b8035906020019184600183028401116401000000008311171561062657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561068957600080fd5b82018360208201111561069b57600080fd5b803590602001918460018302840111640100000000831117156106bd57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561072057600080fd5b82018360208201111561073257600080fd5b8035906020019184600183028401116401000000008311171561075457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156107b757600080fd5b8201836020820111156107c957600080fd5b803590602001918460018302840111640100000000831117156107eb57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561084e57600080fd5b82018360208201111561086057600080fd5b8035906020019184600183028401116401000000008311171561088257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610b8a565b005b8560006108e38886610ce2565b6040518082805190602001908083835b6020831061091657805182526020820191506020810190506020830392506108f3565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600001908051906020019061095f929190610e2b565b5084600061096d8886610ce2565b6040518082805190602001908083835b602083106109a0578051825260208201915060208101905060208303925061097d565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060010190805190602001906109e9929190610e2b565b508060006109f78886610ce2565b6040518082805190602001908083835b60208310610a2a5780518252602082019150602081019050602083039250610a07565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206005019080519060200190610a73929190610e2b565b50505050505050565b60606000826040518082805190602001908083835b60208310610ab45780518252602082019150602081019050602083039250610a91565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206001018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b7e5780601f10610b5357610100808354040283529160200191610b7e565b820191906000526020600020905b815481529060010190602001808311610b6157829003601f168201915b50505050509050919050565b6040518060c00160405280878152602001868152602001858152602001848152602001838152602001828152506000610bc38886610ce2565b6040518082805190602001908083835b60208310610bf65780518252602082019150602081019050602083039250610bd3565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206000820151816000019080519060200190610c45929190610eab565b506020820151816001019080519060200190610c62929190610eab565b506040820151816002019080519060200190610c7f929190610eab565b506060820151816003019080519060200190610c9c929190610eab565b506080820151816004019080519060200190610cb9929190610eab565b5060a0820151816005019080519060200190610cd6929190610eab565b50905050505050505050565b6060808390506060839050606081518351016040519080825280601f01601f191660200182016040528015610d265781602001600182028038833980820191505090505b5090506060819050600080905060008090505b8551811015610da757858181518110610d4e57fe5b602001015160f81c60f81b838380600101945081518110610d6b57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080600101915050610d39565b5060008090505b8451811015610e1c57848181518110610dc357fe5b602001015160f81c60f81b838380600101945081518110610de057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080600101915050610dae565b50829550505050505092915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610e6c57805160ff1916838001178555610e9a565b82800160010185558215610e9a579182015b82811115610e99578251825591602001919060010190610e7e565b5b509050610ea79190610f2b565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610eec57805160ff1916838001178555610f1a565b82800160010185558215610f1a579182015b82811115610f19578251825591602001919060010190610efe565b5b509050610f279190610f2b565b5090565b610f4d91905b80821115610f49576000816000905550600101610f31565b5090565b9056fea165627a7a72305820bb07d9ce4d73d23ad70dd34a17411767a2dc73c8fa88fba186e52d8f3efbd3ea0029”);
String rawTx = null;
try {
rawTx = tx.sign(“sign”);
} catch (IOException e) {
e.printStackTrace();
}
CITAj service = CITAj.build(new HttpService(“http://121.196.200.225:1337”));
try {
AppSendTransaction result = service.appSendRawTransaction(rawTx).send();
System.out.println(result.isEmpty());
System.out.println(result.getSendTransactionResult());
} catch (IOException e) {
e.printStackTrace();
}
}

CITAj service = CITAj.build(new HttpService(“http://121.196.200.225:1337/”));

在这行代码之前,加一行代码,打开 http 请求的 log 开关。

HttpService.setDebug(true);

然后开一下最原始的 Http 请求日志,麻烦把日志贴一下,谢谢。

{“jsonrpc”:“2.0”,“id”:0,“error”:{“code”:-32006,“message”:“BadChainId”}}

ChainId 有误

先用 getMetaData 看一下 chainId 是多少。

我用你们的测试网络 curl -X POST --data ‘{“jsonrpc”:“2.0”,“method”:“getMetaData”,“params”:[“0xff”],“id”:0}’ 121.196.200.225:1337
结果:
{“jsonrpc”:“2.0”,“id”:0,“error”:{“code”:-32003,“message”:“Query chain name failed”}}
用我本地的 curl -X POST --data ‘{“jsonrpc”:“2.0”,“method”:“getMetaData”,“params”:[“0xff”],“id”:1}’ 127.0.0.1:1337
结果
{“jsonrpc”:“2.0”,“id”:1,“result”:{“chainId”:0,“chainIdV1”:“0x1”,“chainName”:“test-chain”,“operator”:“test-operator”,“website”:“https://www.example.com”,“genesisTimestamp”:1555661275807,“validators”:[“0x012fb22a531da103f55b4d1806156837c4ef225a”,“0x3a991f59c42afc3a5a3a39723c6b0d938e2261c4”,“0xf6615342b6d86c27029aee5ea46dd39784a24d4d”,“0xdaff028df55cd9ecb4b9b9e296f8bc88a7636f0f”],“blockInterval”:3000,“tokenName”:“CITA Test Token”,“tokenSymbol”:“CTT”,“tokenAvatar”:“https://cdn.cryptape.com/icon_cita.png",“version”:1,"economicalModel”:0}}.
会是因为chainId类型吗?我传的是BigInteger.ZERO

curl -X POST --data ‘{“jsonrpc”:“2.0”,“method”:“getMetaData”,“params”:[“latest”],“id”:1}’ 121.196.200.225:1337 使用这个查询吧,查询最新块

curl -X POST --data ‘{“jsonrpc”:“2.0”,“method”:“getMetaData”,“params”:[“latest”],“id”:1}’ 121.196.200.225:1337

{“jsonrpc”:“2.0”,“id”:1,“result”:{“chainId”:0,“chainIdV1”:“0x1”,“chainName”:“test-chain”,“operator”:“test-operator”,“website”:“https://www.example.com”,“genesisTimestamp”:1541058686340,“validators”:[“0xc489d5cb6f497e4708cc8c3805473b9528f83c7a”,“0x497c68f02bbe335cc879356af120371ebf6cbc29”,“0x6fbb4c8bb76ace631d634545fe39cbee979dd08e”,“0x3c0f681e13f18b51d5350823eae45cb502231cf4”],“blockInterval”:3000,“tokenName”:“CITA Test Token”,“tokenSymbol”:“CTT”,“tokenAvatar”:“https://cdn.cryptape.com/icon_cita.png",“version”:1,"economicalModel”:1}}
chainId是0没问题啊