11import axios from 'axios' ;
22
3+ import type {
4+ GetBlockResponse ,
5+ GetCode ,
6+ GetContractAddressesResponse ,
7+ GetTransactionResponse ,
8+ GetTransactionStatusResponse ,
9+ } from './index.d' ;
10+
311const API_URL : string = 'https://alpha2.starknet.io/' ;
412const FEEDER_GATEWAY_URL : string = `${ API_URL } /feeder_gateway` ;
513const GATEWAY_URL : string = `${ API_URL } /gateway` ;
@@ -8,19 +16,20 @@ const GATEWAY_URL: string = `${API_URL}/gateway`;
816 * Gets the smart contract address on the goerli testnet.
917 *
1018 * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
11- * @returns starknet smart contract address
19+ * @returns starknet smart contract addresses
1220 */
13- export function getContractAddresses ( ) : Promise < object > {
21+ export function getContractAddresses ( ) : Promise < GetContractAddressesResponse > {
1422 return new Promise ( ( resolve , reject ) => {
1523 axios
16- . get ( `${ FEEDER_GATEWAY_URL } /get_contract_addresses` )
17- . then ( ( resp : any ) => {
24+ . get < GetContractAddressesResponse > ( `${ FEEDER_GATEWAY_URL } /get_contract_addresses` )
25+ . then ( ( resp ) => {
1826 resolve ( resp . data ) ;
1927 } )
2028 . catch ( reject ) ;
2129 } ) ;
2230}
2331
32+ // TODO: add proper type
2433/**
2534 * Calls a function on the StarkNet contract.
2635 *
@@ -49,10 +58,10 @@ export function callContract(invokeTx: object, blockId: number): Promise<object>
4958 * @param blockId
5059 * @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
5160 */
52- export function getBlock ( blockId : number ) : Promise < object > {
61+ export function getBlock ( blockId : number ) : Promise < GetBlockResponse > {
5362 return new Promise ( ( resolve , reject ) => {
5463 axios
55- . get ( `${ FEEDER_GATEWAY_URL } /get_block?blockId=${ blockId } ` )
64+ . get < GetBlockResponse > ( `${ FEEDER_GATEWAY_URL } /get_block?blockId=${ blockId } ` )
5665 . then ( ( resp : any ) => {
5766 resolve ( resp . data ) ;
5867 } )
@@ -67,19 +76,22 @@ export function getBlock(blockId: number): Promise<object> {
6776 *
6877 * @param contractAddress
6978 * @param blockId
70- * @returns ABI of compiled contract in JSON
79+ * @returns Bytecode and ABI of compiled contract
7180 */
72- export function getCode ( contractAddress : string , blockId : number ) : Promise < object > {
81+ export function getCode ( contractAddress : string , blockId : number ) : Promise < GetCode > {
7382 return new Promise ( ( resolve , reject ) => {
7483 axios
75- . get ( `${ FEEDER_GATEWAY_URL } /get_code?contractAddress=${ contractAddress } &blockId=${ blockId } ` )
76- . then ( ( resp : any ) => {
84+ . get < GetCode > (
85+ `${ FEEDER_GATEWAY_URL } /get_code?contractAddress=${ contractAddress } &blockId=${ blockId } `
86+ )
87+ . then ( ( resp ) => {
7788 resolve ( resp . data ) ;
7889 } )
7990 . catch ( reject ) ;
8091 } ) ;
8192}
8293
94+ // TODO: add proper type
8395/**
8496 * Gets the contract's storage variable at a specific key.
8597 *
@@ -115,11 +127,13 @@ export function getStorageAt(
115127 * @param txId
116128 * @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
117129 */
118- export function getTransactionStatus ( txId : number ) : Promise < object > {
130+ export function getTransactionStatus ( txId : number ) : Promise < GetTransactionStatusResponse > {
119131 return new Promise ( ( resolve , reject ) => {
120132 axios
121- . get ( `${ FEEDER_GATEWAY_URL } /get_transaction_status?transactionId=${ txId } ` )
122- . then ( ( resp : any ) => {
133+ . get < GetTransactionStatusResponse > (
134+ `${ FEEDER_GATEWAY_URL } /get_transaction_status?transactionId=${ txId } `
135+ )
136+ . then ( ( resp ) => {
123137 resolve ( resp . data ) ;
124138 } )
125139 . catch ( reject ) ;
@@ -134,17 +148,18 @@ export function getTransactionStatus(txId: number): Promise<object> {
134148 * @param txId
135149 * @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
136150 */
137- export function getTransaction ( txId : number ) : Promise < object > {
151+ export function getTransaction ( txId : number ) : Promise < GetTransactionResponse > {
138152 return new Promise ( ( resolve , reject ) => {
139153 axios
140- . get ( `${ FEEDER_GATEWAY_URL } /get_transaction?transactionId=${ txId } ` )
141- . then ( ( resp : any ) => {
154+ . get < GetTransactionResponse > ( `${ FEEDER_GATEWAY_URL } /get_transaction?transactionId=${ txId } ` )
155+ . then ( ( resp ) => {
142156 resolve ( resp . data ) ;
143157 } )
144158 . catch ( reject ) ;
145159 } ) ;
146160}
147161
162+ // TODO: add proper type
148163/**
149164 * Invoke a function on the starknet contract
150165 *
0 commit comments