|
1 | 1 | import fetch from 'cross-fetch'; |
2 | 2 | import urljoin from 'url-join'; |
3 | 3 |
|
4 | | -import { StarknetChainId } from '../constants'; |
| 4 | +import { ONE, StarknetChainId, ZERO } from '../constants'; |
5 | 5 | import { |
6 | 6 | Abi, |
7 | 7 | AddTransactionResponse, |
8 | 8 | Call, |
9 | 9 | CallContractResponse, |
10 | 10 | CompiledContract, |
| 11 | + DeclareContractPayload, |
11 | 12 | DeployContractPayload, |
12 | 13 | Endpoints, |
13 | 14 | GetBlockResponse, |
@@ -309,6 +310,34 @@ export class Provider implements ProviderInterface { |
309 | 310 | return this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex }); |
310 | 311 | } |
311 | 312 |
|
| 313 | + /** |
| 314 | + * Declare a given compiled contract (json) on starknet |
| 315 | + * |
| 316 | + * @param contract - a json object containing the compiled contract |
| 317 | + * @returns a confirmation of sending a transaction on the starknet contract |
| 318 | + */ |
| 319 | + public declareContract( |
| 320 | + payload: DeclareContractPayload, |
| 321 | + _abi?: Abi |
| 322 | + ): Promise<AddTransactionResponse> { |
| 323 | + const parsedContract = |
| 324 | + typeof payload.contract === 'string' |
| 325 | + ? (parse(payload.contract) as CompiledContract) |
| 326 | + : payload.contract; |
| 327 | + const contractDefinition = { |
| 328 | + ...parsedContract, |
| 329 | + program: compressProgram(parsedContract.program), |
| 330 | + }; |
| 331 | + |
| 332 | + return this.fetchEndpoint('add_transaction', undefined, { |
| 333 | + type: 'DECLARE', |
| 334 | + contract_class: contractDefinition, |
| 335 | + nonce: toHex(ZERO), |
| 336 | + signature: [], |
| 337 | + sender_address: toHex(ONE), |
| 338 | + }); |
| 339 | + } |
| 340 | + |
312 | 341 | /** |
313 | 342 | * Deploys a given compiled contract (json) to starknet |
314 | 343 | * |
|
0 commit comments