|
| 1 | +StarkNet.js Docs |
| 2 | + |
| 3 | +# StarkNet.js Docs |
| 4 | + |
| 5 | +## Table of contents |
| 6 | + |
| 7 | +### Functions |
| 8 | + |
| 9 | +- [addTransaction](README.md#addtransaction) |
| 10 | +- [callContract](README.md#callcontract) |
| 11 | +- [compressProgram](README.md#compressprogram) |
| 12 | +- [deployContract](README.md#deploycontract) |
| 13 | +- [getBlock](README.md#getblock) |
| 14 | +- [getCode](README.md#getcode) |
| 15 | +- [getContractAddresses](README.md#getcontractaddresses) |
| 16 | +- [getStorageAt](README.md#getstorageat) |
| 17 | +- [getTransaction](README.md#gettransaction) |
| 18 | +- [getTransactionStatus](README.md#gettransactionstatus) |
| 19 | + |
| 20 | +## Functions |
| 21 | + |
| 22 | +### addTransaction |
| 23 | + |
| 24 | +▸ **addTransaction**(`tx`): `Promise`<`AddTransactionResponse`\> |
| 25 | + |
| 26 | +Invoke a function on the starknet contract |
| 27 | + |
| 28 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17) |
| 29 | + |
| 30 | +#### Parameters |
| 31 | + |
| 32 | +| Name | Type | Description | |
| 33 | +| :--- | :------------ | :------------------------------ | |
| 34 | +| `tx` | `Transaction` | transaction to be invoked (WIP) | |
| 35 | + |
| 36 | +#### Returns |
| 37 | + |
| 38 | +`Promise`<`AddTransactionResponse`\> |
| 39 | + |
| 40 | +a confirmation of invoking a function on the starknet contract |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +### callContract |
| 45 | + |
| 46 | +▸ **callContract**(`invokeTx`, `blockId`): `Promise`<`object`\> |
| 47 | + |
| 48 | +Calls a function on the StarkNet contract. |
| 49 | + |
| 50 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25) |
| 51 | + |
| 52 | +#### Parameters |
| 53 | + |
| 54 | +| Name | Type | Description | |
| 55 | +| :--------- | :------- | :------------------------------ | |
| 56 | +| `invokeTx` | `object` | transaction to be invoked (WIP) | |
| 57 | +| `blockId` | `number` | | |
| 58 | + |
| 59 | +#### Returns |
| 60 | + |
| 61 | +`Promise`<`object`\> |
| 62 | + |
| 63 | +the result of the function on the smart contract. |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +### compressProgram |
| 68 | + |
| 69 | +▸ **compressProgram**(`jsonProgram`): `CompressedProgram` |
| 70 | + |
| 71 | +Function to compress compiled cairo program |
| 72 | + |
| 73 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/gateway/transaction.py#L54-L58) |
| 74 | + |
| 75 | +#### Parameters |
| 76 | + |
| 77 | +| Name | Type | Description | |
| 78 | +| :------------ | :------------------- | :------------------------------------------------ | |
| 79 | +| `jsonProgram` | `string` \| `object` | json file representing the compiled cairo program | |
| 80 | + |
| 81 | +#### Returns |
| 82 | + |
| 83 | +`CompressedProgram` |
| 84 | + |
| 85 | +Compressed cairo program |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +### deployContract |
| 90 | + |
| 91 | +▸ **deployContract**(`contract`, `address?`): `Promise`<`AddTransactionResponse`\> |
| 92 | + |
| 93 | +Deploys a given compiled contract (json) to starknet |
| 94 | + |
| 95 | +#### Parameters |
| 96 | + |
| 97 | +| Name | Type | Description | |
| 98 | +| :--------- | :----------------------------- | :------------------------------------------------------------------------------------------------- | |
| 99 | +| `contract` | `string` \| `CompiledContract` | a json object containing the compiled contract | |
| 100 | +| `address` | `string` | (optional, defaults to a random address) the address where the contract should be deployed (alpha) | |
| 101 | + |
| 102 | +#### Returns |
| 103 | + |
| 104 | +`Promise`<`AddTransactionResponse`\> |
| 105 | + |
| 106 | +a confirmation of sending a transaction on the starknet contract |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +### getBlock |
| 111 | + |
| 112 | +▸ **getBlock**(`blockId`): `Promise`<`GetBlockResponse`\> |
| 113 | + |
| 114 | +Gets the block information from a block ID. |
| 115 | + |
| 116 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31) |
| 117 | + |
| 118 | +#### Parameters |
| 119 | + |
| 120 | +| Name | Type | |
| 121 | +| :-------- | :------- | |
| 122 | +| `blockId` | `number` | |
| 123 | + |
| 124 | +#### Returns |
| 125 | + |
| 126 | +`Promise`<`GetBlockResponse`\> |
| 127 | + |
| 128 | +the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions } |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +### getCode |
| 133 | + |
| 134 | +▸ **getCode**(`contractAddress`, `blockId`): `Promise`<`GetCode`\> |
| 135 | + |
| 136 | +Gets the code of the deployed contract. |
| 137 | + |
| 138 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36) |
| 139 | + |
| 140 | +#### Parameters |
| 141 | + |
| 142 | +| Name | Type | |
| 143 | +| :---------------- | :------- | |
| 144 | +| `contractAddress` | `string` | |
| 145 | +| `blockId` | `number` | |
| 146 | + |
| 147 | +#### Returns |
| 148 | + |
| 149 | +`Promise`<`GetCode`\> |
| 150 | + |
| 151 | +Bytecode and ABI of compiled contract |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +### getContractAddresses |
| 156 | + |
| 157 | +▸ **getContractAddresses**(): `Promise`<`GetContractAddressesResponse`\> |
| 158 | + |
| 159 | +Gets the smart contract address on the goerli testnet. |
| 160 | + |
| 161 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15) |
| 162 | + |
| 163 | +#### Returns |
| 164 | + |
| 165 | +`Promise`<`GetContractAddressesResponse`\> |
| 166 | + |
| 167 | +starknet smart contract addresses |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +### getStorageAt |
| 172 | + |
| 173 | +▸ **getStorageAt**(`contractAddress`, `key`, `blockId`): `Promise`<`object`\> |
| 174 | + |
| 175 | +Gets the contract's storage variable at a specific key. |
| 176 | + |
| 177 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L38-L46) |
| 178 | + |
| 179 | +#### Parameters |
| 180 | + |
| 181 | +| Name | Type | Description | |
| 182 | +| :---------------- | :------- | :--------------------------------------------------------- | |
| 183 | +| `contractAddress` | `string` | | |
| 184 | +| `key` | `number` | from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP) | |
| 185 | +| `blockId` | `number` | | |
| 186 | + |
| 187 | +#### Returns |
| 188 | + |
| 189 | +`Promise`<`object`\> |
| 190 | + |
| 191 | +the value of the storage variable |
| 192 | + |
| 193 | +--- |
| 194 | + |
| 195 | +### getTransaction |
| 196 | + |
| 197 | +▸ **getTransaction**(`txId`): `Promise`<`GetTransactionResponse`\> |
| 198 | + |
| 199 | +Gets the transaction information from a tx id. |
| 200 | + |
| 201 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58) |
| 202 | + |
| 203 | +#### Parameters |
| 204 | + |
| 205 | +| Name | Type | |
| 206 | +| :----- | :------- | |
| 207 | +| `txId` | `number` | |
| 208 | + |
| 209 | +#### Returns |
| 210 | + |
| 211 | +`Promise`<`GetTransactionResponse`\> |
| 212 | + |
| 213 | +the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? } |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +### getTransactionStatus |
| 218 | + |
| 219 | +▸ **getTransactionStatus**(`txId`): `Promise`<`GetTransactionStatusResponse`\> |
| 220 | + |
| 221 | +Gets the status of a transaction. |
| 222 | + |
| 223 | +[Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52) |
| 224 | + |
| 225 | +#### Parameters |
| 226 | + |
| 227 | +| Name | Type | |
| 228 | +| :----- | :------- | |
| 229 | +| `txId` | `number` | |
| 230 | + |
| 231 | +#### Returns |
| 232 | + |
| 233 | +`Promise`<`GetTransactionStatusResponse`\> |
| 234 | + |
| 235 | +the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN } |
0 commit comments