@YiDo
안녕하세요. 클레이튼 포럼에 질문을 올려주셔서 감사합니다.
조회하려고 하는 블록의 트랜잭션이 0개일 때는 결과가 비어있는 것이 맞습니다.
혹시 data값을 받아오지 못하셨다는 게 아래와 같은 응답을 받으셨다는 것이 맞을까요?
{"jsonrpc":"2.0","id":73,"result":[]}
만약 그렇다면 해당 블록에는 트랜잭션이 없다는 뜻입니다.
Klaytn Scope에서 트랜잭션이 한 개 이상 있는 블록의 해시를 대상으로 조회를 한 번 시도해보시겠어요?
트랜잭션이 한 개 이상 존재한다면 아래와 같은 응답을 받아보실 수 있습니다.
{
"id" : 0,
"jsonrpc" : "2.0",
"result" : [ {
"blockHash" : "0xeb5ce356d33b63c6489e7ac5120822dc82d419cdd197dc6bc0164e550ef74c8b",
"blockNumber" : "0x3c24c96",
"codeFormat" : null,
"contractAddress" : null,
"feePayer" : "0x10f0eaa52a474f0605afbb8c17bb9189e6ed006c",
"feePayerSignatures" : [ {
"v" : "0x7f6",
"r" : "0x80d71ce0d7346901b521ee6f0b5533def1a1890ff6a0aa303c8f5e2aef077081",
"s" : "0x2e7215c480496cbe530a25fda887486e7fe9cb572ef24ff1f1c7b5a481038483"
} ],
"feeRatio" : null,
"from" : "0x0a44f513e8e7b495562ad7cf4c21e6d3695d5365",
"gas" : "0x1c9c380",
"gasPrice" : "0x5d21dba00",
"gasUsed" : "0x520f2",
"humanReadable" : false,
"key" : null,
"input" : "0xb08e5458",
"logs" : [ ],
"logsBloom" : "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"nonce" : "0x0",
"senderTxHash" : "0xbc8ddc00b30cbc505e5f64cccfcf3306ea835f2012cbf5282022bd471310cffc",
"signatures" : [ {
"v" : "0x7f5",
"r" : "0x7e7ee40ae2ad5ca0ed374c78194fb8a738cafe3d192a675c0f5847959bd283ca",
"s" : "0x4400527c04a098a4bbecd441365a3558c97339a2d2b7357bd59cce4d6cc8288a"
} ],
"status" : "0x1",
"to" : "0x57ae2b26f55e332ea8a45e1975971b8a041e7c2c",
"transactionIndex" : "0x0",
"transactionHash" : "0xee0613c8c746a10056a47aab58420004f8d2ac270acf251dc6aced5179586ae4",
"txError" : null,
"type" : "TxTypeFeeDelegatedSmartContractExecution",
"typeInt" : "49",
"value" : "0x0"
} ],
"error" : null,
"rawResponse" : null
}
caver-java를 사용해서 테스트한 소스코드는 아래와 같습니다.
아래 예제는 KAS의 Node API URL을 엔드포인트로 활용하는 예시인데 @YiDo 님 편의에 따라 엔드포인트를 운영하시는 EN으로 하셔도 되고 저처럼 KAS를 가입하신 뒤 활용하실 수 있습니다
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.klaytn.caver.Caver;
import com.klaytn.caver.abi.datatypes.Type;
import com.klaytn.caver.contract.Contract;
import com.klaytn.caver.contract.SendOptions;
import com.klaytn.caver.methods.response.BlockTransactionReceipts;
import com.klaytn.caver.methods.response.TransactionReceipt;
import com.klaytn.caver.wallet.keyring.SingleKeyring;
import okhttp3.Credentials;
import org.web3j.protocol.http.HttpService;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
public class BoilerPlate {
private static final String URL_NODE_API = "https://node-api.klaytnapi.com/v1/klaytn";
private static final String accessKeyId = "<your-access-key-id-generated-by-KAS>"; // e.g. accessKeyId = "KASK1LVNO498YT6KJQFUPY8T";
private static final String secretAccessKey = "aP/reVYHXqjw3EtQrMuJP4A3/hOb69TjnBT3ePKF"; // e.g. secretAccessKey = "<your-secret-access-key-generated-by-KAS>";
private static final String chainId = "1001"; // e.g. chainId = "1001";
public static void main(String[] args) throws IOException {
run();
}
public static void run() {
try {
HttpService httpService = new HttpService(URL_NODE_API);
if (accessKeyId.isEmpty() || secretAccessKey.isEmpty()) {
throw new Exception("accessKeyId and secretAccessKey must not be empty.");
}
httpService.addHeader("Authorization", Credentials.basic(accessKeyId, secretAccessKey));
httpService.addHeader("x-chain-id", chainId);
Caver caver = new Caver(httpService);
BlockTransactionReceipts blockTransactionReceipts = caver.rpc.klay.getBlockReceipts("0xeb5ce356d33b63c6489e7ac5120822dc82d419cdd197dc6bc0164e550ef74c8b").send();
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
System.out.println(ow.writeValueAsString(blockTransactionReceipts));
} catch (Exception e) {
e.printStackTrace();
}
}
}