Web3节点引擎服务 NES
Web3节点引擎服务 NES
- 最新动态
- 产品介绍
- 快速入门
- 用户指南
- 质押指南
-
开发指南
-
以太坊Ethereum节点引擎
- 以太坊Ethereum介绍
- JSON-RPC API请求示例
- 应用程序开发介绍
- 智能合约开发介绍
-
以太坊API列表
- 专享版
-
共享版
- eth_blocknumber
- eth_getBlockByNumber
- eth_getUncleByBlockNumberAndIndex
- eth_getUncleByBlockHashAndIndex
- eth_getUncleCountByBlockNumber
- eth_getUncleCountByBlockHash
- eth_getBlockByHash
- eth_getTransactionByHash
- eth_getTransactionCount
- eth_getTransactionByBlockHashAndIndex
- eth_getTransactionByBlockNumberAndIndex
- eth_getBlockTransactionCountByHash
- eth_getBlockTransactionCountByNumber
- eth_getTransactionReceipt
- eth_sendRawTransaction
- eth_call
- eth_createAccessList
- eth_estimateGas
- eth_feeHistory
- eth_maxPriorityFeePerGas
- eth_gasPrice
- eth_getBalance
- eth_subscribe
- eth_unsubscribe
- eth_getStorageAt
- eth_getCode
- eth_getProof
- eth_getLogs
- eth_getFilterChanges
- eth_getFilterLogs
- eth_newBlockFilter
- eth_newFilter
- eth_newPendingTransactionFilter
- eth_uninstallFilter
- eth_chainId
- web3_sha3
- web3_clientVersion
- net_version
- net_listening
- 波场Tron节点引擎
-
Polygon PoS
- Polygon PoS介绍
- HTTP请求示例
- WebSocket请求示例
-
Polygon PoS API列表
- 专享版
-
共享版
-
Ethereum JSON-RPC API
- eth_blocknumber
- eth_getBlockByNumber
- eth_getUncleByBlockNumberAndIndex
- eth_getUncleByBlockHashAndIndex
- eth_getUncleCountByBlockNumber
- eth_getUncleCountByBlockHash
- eth_getBlockByHash
- eth_getTransactionByHash
- eth_getTransactionCount
- eth_getTransactionByBlockHashAndIndex
- eth_getTransactionByBlockNumberAndIndex
- eth_getBlockTransactionCountByHash
- eth_getBlockTransactionCountByNumber
- eth_getTransactionReceiptsByBlock
- eth_getTransactionReceipt
- eth_sendRawTransaction
- eth_call
- eth_createAccessList
- eth_estimateGas
- eth_feeHistory
- eth_maxPriorityFeePerGas
- eth_gasPrice
- eth_getBalance
- eth_getRootHash
- eth_subscribe
- eth_unsubscribe
- eth_getStorageAt
- eth_accounts
- eth_getCode
- eth_getProof
- eth_getLogs
- eth_getFilterChanges
- eth_getFilterLogs
- eth_newBlockFilter
- eth_newFilter
- eth_newPendingTransactionFilter
- eth_uninstallFilter
- eth_chainId
- web3_sha3
- web3_clientVersion
- Polygon JSON-RPC API
-
Ethereum JSON-RPC API
-
Arbitrum
- Arbitrum介绍
- HTTP请求示例
- WebSocket请求示例
-
Arbitrum API列表
-
共享版
-
Ethereum JSON-RPC API
- eth_blocknumber
- eth_getBlockByNumber
- eth_getUncleByBlockNumberAndIndex
- eth_getUncleByBlockHashAndIndex
- eth_getUncleCountByBlockNumber
- eth_getUncleCountByBlockHash
- eth_getBlockByHash
- eth_getTransactionByHash
- eth_getTransactionCount
- eth_getTransactionByBlockHashAndIndex
- eth_getTransactionByBlockNumberAndIndex
- eth_getBlockTransactionCountByHash
- eth_getBlockTransactionCountByNumber
- eth_syncing
- eth_getTransactionReceipt
- eth_sendRawTransaction
- eth_call
- eth_createAccessList
- eth_estimateGas
- eth_feeHistory
- eth_maxPriorityFeePerGas
- eth_gasPrice
- eth_getBalance
- eth_subscribe
- eth_unsubscribe
- eth_getStorageAt
- eth_accounts
- eth_getCode
- eth_getProof
- eth_getLogs
- eth_getFilterChanges
- eth_getFilterLogs
- eth_newBlockFilter
- eth_newFilter
- eth_newPendingTransactionFilter
- eth_uninstallFilter
- eth_chainId
- web3_sha3
- web3_clientVersion
-
Ethereum JSON-RPC API
-
共享版
-
BNB Smart Chain
- BNB Smart Chain介绍
- HTTP请求示例
- WebSocket请求示例
-
BNB Smart Chain API列表
- 专享版
-
共享版
- eth_blocknumber
- eth_getBlockByNumber
- eth_hashrate
- eth_getUncleCountByBlockNumber
- eth_getUncleCountByBlockHash
- eth_getBlockByHash
- eth_getTransactionByHash
- eth_getTransactionCount
- eth_getTransactionByBlockHashAndIndex
- eth_getTransactionByBlockNumberAndIndex
- eth_getBlockTransactionCountByHash
- eth_getBlockTransactionCountByNumber
- eth_syncing
- eth_getTransactionReceipt
- eth_sendRawTransaction
- eth_call
- eth_mining
- eth_estimateGas
- eth_feeHistory
- eth_maxPriorityFeePerGas
- eth_gasPrice
- eth_getBalance
- eth_subscribe
- eth_unsubscribe
- eth_getStorageAt
- eth_accounts
- eth_getCode
- eth_getProof
- eth_getLogs
- eth_getFilterChanges
- eth_getFilterLogs
- eth_newBlockFilter
- eth_newFilter
- eth_newPendingTransactionFilter
- eth_uninstallFilter
- eth_chainId
- web3_sha3
- web3_clientVersion
- txpool_status
- net_listening
- net_version
- 批量请求
-
以太坊Ethereum节点引擎
- API参考
- 常见问题
- 通用参考
本文导读
展开导读
链接复制成功!
使用trident-sdk发送gRPC请求
trident sdk截止至版本0.7.0,尚未支持tls认证的方式进行gRPC请求,因此需要按照示例代码,通过java反射的方式,打开trident的tls认证进行节点对接。
在节点页面下载证书,将压缩包内的ca.crt证书放在项目内的目录。
在sdk中配置gRPC endpoint,示例代码如下:
import io.gRPC.*; import io.gRPC.stub.MetadataUtils; import org.tron.trident.api.WalletgRPC; import org.tron.trident.api.WalletSoliditygRPC; import org.tron.trident.core.ApiWrapper; import org.tron.trident.core.exceptions.IllegalException; import org.tron.trident.core.key.KeyPair; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; public class Main { public static void main(String[] args) throws IllegalException, IOException, NoSuchFieldException, IllegalAccessException { String gRPCEndpoint = "your-gRPC-endpoint"; String gRPCSolidityEndpoint = "your-gRPCsolidity-endpoint"; String credential = "your-credential"; String hexPrivateKey = "your-hex-private-key"; ApiWrapper wrapper = new ApiWrapper(gRPCEndpoint, gRPCSolidityEndpoint, hexPrivateKey, credential); // modify wallet channel through reflex ChannelCredentials creds = TlsChannelCredentials.newBuilder() .trustManager(new File("your-ca.crt-file-path")) .build(); ManagedChannel channel = gRPC.newChannelBuilder(gRPCEndpoint, creds) .build(); Metadata header = new Metadata(); Metadata.Key<String> key = Metadata.Key.of("TRON-PRO-API-KEY", Metadata.ASCII_STRING_MARSHALLER); header.put(key, credential); setField(ApiWrapper.class, wrapper, "channel", channel); setField(ApiWrapper.class, wrapper, "blockingStub", MetadataUtils.attachHeaders(WalletgRPC.newBlockingStub(channel), header)); // modify walletsolidity channel through reflex ManagedChannel channelSolidity = gRPC.newChannelBuilder(gRPCSolidityEndpoint, creds) .build(); setField(ApiWrapper.class, wrapper, "channelSolidity", channelSolidity); setField(ApiWrapper.class, wrapper, "blockingStubSolidity", MetadataUtils.attachHeaders(WalletSoliditygRPC.newBlockingStub(channelSolidity), header)); // getNowBlock & getNowBlockSolidity test System.out.println(wrapper.getNowBlock()); System.out.println(wrapper.getNowBlockSolidity()); System.out.println("finish"); } private static void setField(Class clazz, Object obj, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); field.set(obj, value); } }
Response example:
父主题: gRPC请求示例