Notice
Recent Posts
Recent Comments
Link
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

번개멍

Web3j 본문

코딩이야기/blockchain

Web3j

번개멍 2023. 10. 24. 16:36
EthChainId chainId = web3j.ethChainId().send();
System.out.println(chainId.getChainId());

현재 체인의 chain Id를 알 수 있다.

BigInteger blockNumber = web3j.ethBlockNumber().send().getBlockNumber();
System.out.println(blockNumber);

현재 블럭의 번호를 알 수 있다.

 

String contractAddress = "${contractAddress}";

Credentials cutromerCreds = Credentials.create("${privateKey}");
TransactionManager cutomerTokenTxManager = new RawTransactionManager(
        web3j, cutromerCreds, 80001);

Event eventContract = com.event.watcher.contract.Event.load(contractAddress, web3j, cutomerTokenTxManager, new DefaultGasProvider());
try {
    eventContract.test().send();
} catch (Exception e) {
    throw new RuntimeException(e);
}
WebSocketService wss = new WebSocketService("{RPC_URL}", false);
try {
    wss.connect();
} catch (ConnectException e) {
    throw new RuntimeException(e);
}
Web3j web3jWss = Web3j.build(wss);

EthFilter ethFilter = new EthFilter(DefaultBlockParameterName.LATEST, DefaultBlockParameterName.LATEST, "{contractAddress}");
org.web3j.abi.datatypes.Event event = new org.web3j.abi.datatypes.Event("Log", Arrays.asList(new TypeReference<Address>(true) {
}, new TypeReference<Utf8String>() {
}));
String topicData = EventEncoder.encode(event);
ethFilter.addSingleTopic(topicData);
web3j.ethLogFlowable(ethFilter).subscribe(e -> {
    System.out.println(e);
}, error -> {
    System.out.println(error);
});
try {
    Thread.sleep(10000000);
} catch (InterruptedException e) {
    throw new RuntimeException(e);
}

'코딩이야기 > blockchain' 카테고리의 다른 글

_mint vs _safeMint 차이점  (0) 2022.12.23
SmartContract 프레임워크 선택  (0) 2022.12.13
ERC20 토큰 발행 및 ERC721 NFT 발행  (0) 2022.11.21
Comments