|
1 | 1 | import axios from 'axios'; |
2 | | -import { gzip } from 'pako'; |
3 | | -import { randomAddress, btoaUniversal } from './utils'; |
| 2 | +import { randomAddress, compressProgram } from './utils'; |
4 | 3 | import type { |
5 | 4 | GetBlockResponse, |
6 | 5 | GetCode, |
7 | 6 | GetContractAddressesResponse, |
8 | 7 | GetTransactionResponse, |
9 | 8 | GetTransactionStatusResponse, |
10 | | - CompressedProgram, |
11 | 9 | Transaction, |
12 | 10 | AddTransactionResponse, |
13 | 11 | CompiledContract, |
@@ -183,21 +181,20 @@ export function addTransaction(tx: Transaction): Promise<AddTransactionResponse> |
183 | 181 | }); |
184 | 182 | } |
185 | 183 |
|
186 | | -export function compressProgram(program: string): CompressedProgram { |
187 | | - const json = JSON.parse(program); |
188 | | - const stringified = JSON.stringify(json); |
189 | | - const compressedProgram = gzip(stringified); |
190 | | - const base64 = btoaUniversal(compressedProgram); |
191 | | - return base64; |
192 | | -} |
193 | | - |
| 184 | +/** |
| 185 | + * Deploys a given compiled contract (json) to starknet |
| 186 | + * |
| 187 | + * @param contract - a json object containing the compiled contract |
| 188 | + * @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha) |
| 189 | + * @returns a confirmation of sending a transaction on the starknet contract |
| 190 | + */ |
194 | 191 | export function deployContract( |
195 | 192 | contract: CompiledContract, |
196 | 193 | address: string = randomAddress() |
197 | 194 | ): Promise<AddTransactionResponse> { |
198 | 195 | const contractDefinition = { |
199 | 196 | ...contract, |
200 | | - program: compressProgram(JSON.stringify(contract.program)), |
| 197 | + program: compressProgram(contract.program), |
201 | 198 | }; |
202 | 199 |
|
203 | 200 | return addTransaction({ |
|
0 commit comments