@@ -61,6 +61,7 @@ import { AppSpec, arc32ToArc56 } from './app-spec'
61
61
import {
62
62
AppCallMethodCall ,
63
63
AppCallParams ,
64
+ AppCreateMethodCall ,
64
65
AppDeleteMethodCall ,
65
66
AppDeleteParams ,
66
67
AppMethodCall ,
@@ -260,9 +261,9 @@ export interface FundAppAccountParams {
260
261
/** Source maps for an Algorand app */
261
262
export interface AppSourceMaps {
262
263
/** The source map of the approval program */
263
- approvalSourceMap : SourceMapExport
264
+ approvalSourceMap : algosdk . ProgramSourceMap
264
265
/** The source map of the clear program */
265
- clearSourceMap : SourceMapExport
266
+ clearSourceMap : algosdk . ProgramSourceMap
266
267
}
267
268
268
269
export interface SourceMapExport {
@@ -353,7 +354,14 @@ export type CallOnComplete = {
353
354
354
355
/** AppClient common parameters for a bare app call */
355
356
export type AppClientBareCallParams = Expand <
356
- Omit < CommonAppCallParams , 'appId' | 'sender' | 'onComplete' > & {
357
+ Omit < CommonAppCallParams , 'appId' | 'sender' > & {
358
+ /** The address of the account sending the transaction, if undefined then the app client's defaultSender is used. */
359
+ sender ?: Address | string
360
+ }
361
+ >
362
+
363
+ export type AppClientBareCreateParams = Expand <
364
+ Omit < CommonAppCallParams , 'appId' | 'sender' > & {
357
365
/** The address of the account sending the transaction, if undefined then the app client's defaultSender is used. */
358
366
sender ?: Address | string
359
367
}
@@ -1193,6 +1201,15 @@ export class AppClient {
1193
1201
OnApplicationComplete . UpdateApplicationOC ,
1194
1202
) as AppUpdateParams
1195
1203
} ,
1204
+ create : async ( params ?: AppClientBareCallParams & AppClientCompilationParams ) => {
1205
+ return this . getBareParams (
1206
+ {
1207
+ ...params ,
1208
+ ...( await this . compile ( params ) ) ,
1209
+ } ,
1210
+ params ?. onComplete ,
1211
+ ) as AppUpdateParams
1212
+ } ,
1196
1213
/** Return params for an opt-in call */
1197
1214
optIn : ( params ?: AppClientBareCallParams ) => {
1198
1215
return this . getBareParams ( params , OnApplicationComplete . OptInOC ) as AppCallParams
@@ -1222,6 +1239,9 @@ export class AppClient {
1222
1239
update : async ( params ?: AppClientBareCallParams & AppClientCompilationParams ) => {
1223
1240
return this . _algorand . createTransaction . appUpdate ( await this . params . bare . update ( params ) )
1224
1241
} ,
1242
+ create : async ( params ?: AppClientBareCallParams & AppClientCompilationParams ) => {
1243
+ return this . _algorand . createTransaction . appCreate ( await this . params . bare . update ( params ) )
1244
+ } ,
1225
1245
/** Returns a transaction for an opt-in call */
1226
1246
optIn : ( params ?: AppClientBareCallParams ) => {
1227
1247
return this . _algorand . createTransaction . appCall ( this . params . bare . optIn ( params ) )
@@ -1255,6 +1275,16 @@ export class AppClient {
1255
1275
...( compiled as Partial < AppCompilationResult > ) ,
1256
1276
}
1257
1277
} ,
1278
+ create : async ( params ?: AppClientBareCallParams & AppClientCompilationParams & SendParams ) => {
1279
+ const compiled = await this . compile ( params )
1280
+ const results = {
1281
+ ...( await this . _algorand . send . appCreate ( await this . params . bare . create ( params ) ) ) ,
1282
+ ...( compiled as Partial < AppCompilationResult > ) ,
1283
+ }
1284
+
1285
+ this . _appId = results . appId
1286
+ return results
1287
+ } ,
1258
1288
/** Signs and sends an opt-in call */
1259
1289
optIn : ( params ?: AppClientBareCallParams & SendParams ) => {
1260
1290
return this . _algorand . send . appCall ( this . params . bare . optIn ( params ) )
@@ -1307,6 +1337,19 @@ export class AppClient {
1307
1337
OnApplicationComplete . UpdateApplicationOC ,
1308
1338
) ) satisfies AppUpdateMethodCall
1309
1339
} ,
1340
+ create : async ( params : AppClientMethodCallParams & AppClientCompilationParams ) => {
1341
+ if ( params . onComplete === OnApplicationComplete . ClearStateOC ) {
1342
+ throw new Error ( `Cannot create with an OnComplete value of ${ params . onComplete } ` )
1343
+ }
1344
+
1345
+ return ( await this . getABIParams (
1346
+ {
1347
+ ...params ,
1348
+ ...( await this . compile ( params ) ) ,
1349
+ } ,
1350
+ params . onComplete ,
1351
+ ) ) satisfies AppCreateMethodCall
1352
+ } ,
1310
1353
/**
1311
1354
* Return params for an opt-in ABI call
1312
1355
* @param params The parameters for the opt-in ABI method call
@@ -1364,6 +1407,24 @@ export class AppClient {
1364
1407
...( compiled as Partial < AppCompilationResult > ) ,
1365
1408
}
1366
1409
} ,
1410
+ /**
1411
+ * Sign and send transactions for an update ABI call, including deploy-time TEAL template replacements and compilation if provided
1412
+ * @param params The parameters for the update ABI method call
1413
+ * @returns The result of sending the update ABI method call
1414
+ */
1415
+ create : async ( params : AppClientMethodCallParams & AppClientCompilationParams & SendParams ) => {
1416
+ const compiled = await this . compile ( params )
1417
+ const results = {
1418
+ ...( await this . processMethodCallReturn (
1419
+ this . _algorand . send . appCreateMethodCall ( await this . params . create ( { ...params } ) ) ,
1420
+ getArc56Method ( params . method , this . _appSpec ) ,
1421
+ ) ) ,
1422
+ ...( compiled as Partial < AppCompilationResult > ) ,
1423
+ }
1424
+
1425
+ this . _appId = results . appId
1426
+ return results
1427
+ } ,
1367
1428
/**
1368
1429
* Sign and send transactions for an opt-in ABI call
1369
1430
* @param params The parameters for the opt-in ABI method call
@@ -1477,6 +1538,9 @@ export class AppClient {
1477
1538
update : async ( params : AppClientMethodCallParams & AppClientCompilationParams ) => {
1478
1539
return this . _algorand . createTransaction . appUpdateMethodCall ( await this . params . update ( params ) )
1479
1540
} ,
1541
+ create : async ( params : AppClientMethodCallParams & AppClientCompilationParams ) => {
1542
+ return this . _algorand . createTransaction . appCreateMethodCall ( await this . params . update ( params ) )
1543
+ } ,
1480
1544
/**
1481
1545
* Return transactions for an opt-in ABI call
1482
1546
* @param params The parameters for the opt-in ABI method call
@@ -1534,7 +1598,7 @@ export class AppClient {
1534
1598
private getBareParams <
1535
1599
TParams extends { sender ?: Address | string ; signer ?: TransactionSigner | TransactionSignerAccount } | undefined ,
1536
1600
TOnComplete extends OnApplicationComplete ,
1537
- > ( params : TParams , onComplete : TOnComplete ) {
1601
+ > ( params : TParams , onComplete ? : TOnComplete ) {
1538
1602
return {
1539
1603
...params ,
1540
1604
appId : this . _appId ,
@@ -1552,7 +1616,7 @@ export class AppClient {
1552
1616
args ?: AppClientMethodCallParams [ 'args' ]
1553
1617
} ,
1554
1618
TOnComplete extends OnApplicationComplete ,
1555
- > ( params : TParams , onComplete : TOnComplete ) {
1619
+ > ( params : TParams , onComplete ? : TOnComplete ) {
1556
1620
const sender = this . getSender ( params . sender )
1557
1621
const method = getArc56Method ( params . method , this . _appSpec )
1558
1622
const args = await this . getABIArgsWithDefaultValues ( params . method , params . args , sender )
0 commit comments