1
+ const axios = require ( 'axios' ) . default ;
2
+ const SHA256 = require ( '@aws-crypto/sha256-js' ) . Sha256
3
+ const defaultProvider = require ( '@aws-sdk/credential-provider-node' ) . defaultProvider
4
+ const HttpRequest = require ( '@aws-sdk/protocol-http' ) . HttpRequest
5
+ const SignatureV4 = require ( '@aws-sdk/signature-v4' ) . SignatureV4
6
+
7
+ // define a signer object with AWS service name, credentials, and region
8
+ const signer = new SignatureV4 ( {
9
+ credentials : defaultProvider ( ) ,
10
+ service : 'managedblockchain-query' ,
11
+ region : 'us-east-1' ,
12
+ sha256 : SHA256 ,
13
+ } ) ;
14
+
15
+ const queryRequest = async ( path , data ) => {
16
+ //query endpoint
17
+ let queryEndpoint = `https://managedblockchain-query.us-east-1.amazonaws.com/${ path } ` ;
18
+
19
+ // parse the URL into its component parts (e.g. host, path)
20
+ const url = new URL ( queryEndpoint ) ;
21
+
22
+ // create an HTTP Request object
23
+ const req = new HttpRequest ( {
24
+ hostname : url . hostname . toString ( ) ,
25
+ path : url . pathname . toString ( ) ,
26
+ body : JSON . stringify ( data ) ,
27
+ method : 'POST' ,
28
+ headers : {
29
+ 'Content-Type' : 'application/json' ,
30
+ 'Accept-Encoding' : 'gzip' ,
31
+ host : url . hostname ,
32
+ }
33
+ } ) ;
34
+
35
+
36
+ // use AWS SignatureV4 utility to sign the request, extract headers and body
37
+ const signedRequest = await signer . sign ( req , { signingDate : new Date ( ) } ) ;
38
+
39
+ try {
40
+ //make the request using axios
41
+ const response = await axios ( { ...signedRequest , url : queryEndpoint , data : data } )
42
+
43
+ console . log ( response . data )
44
+ } catch ( error ) {
45
+ console . error ( 'Something went wrong: ' , error )
46
+ throw error
47
+ }
48
+
49
+
50
+ }
51
+
52
+
53
+ let methodArg = 'get-token-balance' ;
54
+
55
+ let dataArg = {
56
+ // " atBlockchainInstant": {
57
+ // "time": 1688071493
58
+ // }, // (Optional)
59
+ "ownerIdentifier" : {
60
+ "address" : "0x02E6C1d540d17BcD8A47596390E9f1d3d25041d1" // 지갑 혹은 컨트랙트 주소
61
+ } ,
62
+ "tokenIdentifier" : {
63
+ // "contractAddress":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE********", //USDC contract address (Optional)
64
+ "network" :"ETHEREUM_MAINNET" ,
65
+ "tokenId" : "eth"
66
+ }
67
+ }
68
+
69
+ //Run the query request.
70
+ queryRequest ( methodArg , dataArg ) ;
0 commit comments