diff --git a/examples/generators/production_python_smart_contract_typescript/.algokit/generators/create_contract/smart_contracts/{{ contract_name }}/deploy-config.ts.j2 b/examples/generators/production_python_smart_contract_typescript/.algokit/generators/create_contract/smart_contracts/{{ contract_name }}/deploy-config.ts.j2 index ac114cc..bd3ad2d 100644 --- a/examples/generators/production_python_smart_contract_typescript/.algokit/generators/create_contract/smart_contracts/{{ contract_name }}/deploy-config.ts.j2 +++ b/examples/generators/production_python_smart_contract_typescript/.algokit/generators/create_contract/smart_contracts/{{ contract_name }}/deploy-config.ts.j2 @@ -1,5 +1,5 @@ import * as algokit from '@algorandfoundation/algokit-utils' -import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' +import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' // Below is a showcase of various deployment options you can use in TypeScript Client export async function deploy() { @@ -7,27 +7,27 @@ export async function deploy() { const algorand = algokit.AlgorandClient.fromEnvironment() const deployer = await algorand.account.fromEnvironment('DEPLOYER') - - const appClient = algorand.client.getTypedAppClientByCreatorAndName({{ contract_name.split('_')|map('capitalize')|join }}Client, { - sender: deployer, - creatorAddress: deployer.addr, - }) - const app = await appClient.deploy({ - onSchemaBreak: 'append', - onUpdate: 'append', + const factory = algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, { + defaultSender: deployer.addr, }) + const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' }) + // If app was just created fund the app account - if (['create', 'replace'].includes(app.operationPerformed)) { + if (['create', 'replace'].includes(result.operationPerformed)) { await algorand.send.payment({ - amount: algokit.algos(1), + amount: (1).algo(), sender: deployer.addr, receiver: app.appAddress, }) } - const method = 'hello' - const response = await appClient.hello({ name: 'world' }) - console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`) + const method = 'hello' + const response = await appClient.send.hello({ + args: { name: 'world' }, + }) + console.log( + `Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`, + ) } diff --git a/examples/generators/production_python_smart_contract_typescript/package.json b/examples/generators/production_python_smart_contract_typescript/package.json index e64561d..6b832f0 100644 --- a/examples/generators/production_python_smart_contract_typescript/package.json +++ b/examples/generators/production_python_smart_contract_typescript/package.json @@ -14,11 +14,12 @@ "npm": ">=9.0" }, "dependencies": { - "@algorandfoundation/algokit-utils": "^6.0.2", + "@algorandfoundation/algokit-utils": "7.0.0-beta.14", + "@algorandfoundation/algokit-utils-debug": "v1.0.2-beta.2", "algosdk": "^2.7.0" }, "devDependencies": { - "@algorandfoundation/algokit-client-generator": "^3.0.3", + "@algorandfoundation/algokit-client-generator": "v4.0.0-beta.5", "@types/jest": "^29.5.11", "dotenv": "^16.0.3", "prettier": "^2.8.4", diff --git a/examples/generators/production_python_smart_contract_typescript/smart_contracts/cool_contract/deploy-config.ts b/examples/generators/production_python_smart_contract_typescript/smart_contracts/cool_contract/deploy-config.ts index a5dc036..d629083 100644 --- a/examples/generators/production_python_smart_contract_typescript/smart_contracts/cool_contract/deploy-config.ts +++ b/examples/generators/production_python_smart_contract_typescript/smart_contracts/cool_contract/deploy-config.ts @@ -1,5 +1,5 @@ import * as algokit from '@algorandfoundation/algokit-utils' -import { CoolContractClient } from '../artifacts/cool_contract/CoolContractClient' +import { CoolContractFactory } from '../artifacts/cool_contract/CoolContractClient' // Below is a showcase of various deployment options you can use in TypeScript Client export async function deploy() { @@ -7,27 +7,27 @@ export async function deploy() { const algorand = algokit.AlgorandClient.fromEnvironment() const deployer = await algorand.account.fromEnvironment('DEPLOYER') - - const appClient = algorand.client.getTypedAppClientByCreatorAndName(CoolContractClient, { - sender: deployer, - creatorAddress: deployer.addr, - }) - const app = await appClient.deploy({ - onSchemaBreak: 'append', - onUpdate: 'append', + const factory = algorand.client.getTypedAppFactory(CoolContractFactory, { + defaultSender: deployer.addr, }) + const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' }) + // If app was just created fund the app account - if (['create', 'replace'].includes(app.operationPerformed)) { + if (['create', 'replace'].includes(result.operationPerformed)) { await algorand.send.payment({ - amount: algokit.algos(1), + amount: (1).algo(), sender: deployer.addr, receiver: app.appAddress, }) } - const method = 'hello' - const response = await appClient.hello({ name: 'world' }) - console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`) + const method = 'hello' + const response = await appClient.send.hello({ + args: { name: 'world' }, + }) + console.log( + `Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`, + ) } diff --git a/examples/generators/production_python_smart_contract_typescript/smart_contracts/hello_world/deploy-config.ts b/examples/generators/production_python_smart_contract_typescript/smart_contracts/hello_world/deploy-config.ts index 5df7a31..e0608c9 100644 --- a/examples/generators/production_python_smart_contract_typescript/smart_contracts/hello_world/deploy-config.ts +++ b/examples/generators/production_python_smart_contract_typescript/smart_contracts/hello_world/deploy-config.ts @@ -1,5 +1,5 @@ import * as algokit from '@algorandfoundation/algokit-utils' -import { HelloWorldClient } from '../artifacts/hello_world/HelloWorldClient' +import { HelloWorldFactory } from '../artifacts/hello_world/HelloWorldClient' // Below is a showcase of various deployment options you can use in TypeScript Client export async function deploy() { @@ -8,26 +8,26 @@ export async function deploy() { const algorand = algokit.AlgorandClient.fromEnvironment() const deployer = await algorand.account.fromEnvironment('DEPLOYER') - const appClient = algorand.client.getTypedAppClientByCreatorAndName(HelloWorldClient, { - sender: deployer, - creatorAddress: deployer.addr, + const factory = algorand.client.getTypedAppFactory(HelloWorldFactory, { + defaultSender: deployer.addr, }) - const app = await appClient.deploy({ - onSchemaBreak: 'append', - onUpdate: 'append', - }) + const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' }) // If app was just created fund the app account - if (['create', 'replace'].includes(app.operationPerformed)) { + if (['create', 'replace'].includes(result.operationPerformed)) { await algorand.send.payment({ - amount: algokit.algos(1), + amount: (1).algo(), sender: deployer.addr, - receiver: app.appAddress, + receiver: appClient.appAddress, }) } - const method = 'hello' - const response = await appClient.hello({ name: 'world' }) - console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`) + const method = 'hello' + const response = await appClient.send.hello({ + args: { name: 'world' }, + }) + console.log( + `Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`, + ) } diff --git a/examples/generators/production_python_smart_contract_typescript/smart_contracts/index.ts b/examples/generators/production_python_smart_contract_typescript/smart_contracts/index.ts index 6955e33..623ca2b 100644 --- a/examples/generators/production_python_smart_contract_typescript/smart_contracts/index.ts +++ b/examples/generators/production_python_smart_contract_typescript/smart_contracts/index.ts @@ -2,6 +2,7 @@ import * as fs from 'fs' import * as path from 'path' import { consoleLogger } from '@algorandfoundation/algokit-utils/types/logging' import * as algokit from '@algorandfoundation/algokit-utils' +// import { registerDebugEventHandlers } from '@algorandfoundation/algokit-utils-debug' // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger // Uncomment the debug and traceAll options to enable auto generation of AVM Debugger compliant sourceMap and simulation trace file. // Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of Algorand transactions in atomic groups -> https://github.com/algorandfoundation/algokit-avm-vscode-Debugger @@ -11,6 +12,7 @@ algokit.Config.configure({ // debug: true, // traceAll: true, }) +// registerDebugEventHandlers() // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger // base directory const baseDir = path.resolve(__dirname) diff --git a/examples/generators/production_python_smart_contract_typescript/tests/hello-world.spec.ts b/examples/generators/production_python_smart_contract_typescript/tests/hello-world.spec.ts index 0c99f4b..c2ce598 100644 --- a/examples/generators/production_python_smart_contract_typescript/tests/hello-world.spec.ts +++ b/examples/generators/production_python_smart_contract_typescript/tests/hello-world.spec.ts @@ -1,7 +1,8 @@ import { algorandFixture } from '@algorandfoundation/algokit-utils/testing' -import { HelloWorldClient } from '../smart_contracts/artifacts/hello_world/HelloWorldClient' +import { HelloWorldFactory } from '../smart_contracts/artifacts/hello_world/HelloWorldClient' import { Account, Algodv2, Indexer } from 'algosdk' import * as algokit from '@algorandfoundation/algokit-utils' +import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account' describe('hello world contract', () => { const localnet = algorandFixture() @@ -13,39 +14,36 @@ describe('hello world contract', () => { }) beforeEach(localnet.beforeEach) - const deploy = async (account: Account, algod: Algodv2, indexer: Indexer) => { - const client = new HelloWorldClient( - { - resolveBy: 'creatorAndName', - findExistingUsing: indexer, - sender: account, - creatorAddress: account.addr, - }, - algod, - ) - await client.deploy({ - onSchemaBreak: 'append', - onUpdate: 'append', + const deploy = async (account: Account & TransactionSignerAccount) => { + const factory = localnet.algorand.client.getTypedAppFactory(HelloWorldFactory, { + defaultSender: account.addr, + defaultSigner: account.signer, }) - return { client } + + const { appClient } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' }) + return { client: appClient } } test('says hello', async () => { - const { algod, indexer, testAccount } = localnet.context - const { client } = await deploy(testAccount, algod, indexer) + const { testAccount } = localnet.context + const { client } = await deploy(testAccount) - const result = await client.hello({ name: 'World' }) + const result = await client.send.hello({ args: { name: 'World' } }) expect(result.return).toBe('Hello, World') }) test('simulate says hello with correct budget consumed', async () => { - const { algod, indexer, testAccount } = localnet.context - const { client } = await deploy(testAccount, algod, indexer) - const result = await client.compose().hello({ name: 'World' }).hello({ name: 'Jane' }).simulate() + const { testAccount } = localnet.context + const { client } = await deploy(testAccount) + const result = await client + .newGroup() + .hello({ args: { name: 'World' } }) + .hello({ args: { name: 'Jane' } }) + .simulate() - expect(result.methodResults[0].returnValue).toBe('Hello, World') - expect(result.methodResults[1].returnValue).toBe('Hello, Jane') + expect(result.returns[0]).toBe('Hello, World') + expect(result.returns[1]).toBe('Hello, Jane') expect(result.simulateResponse.txnGroups[0].appBudgetConsumed).toBeLessThan(100) }) }) diff --git a/template_content/.algokit/generators/create_contract/smart_contracts/{% raw %}{{ contract_name }}{% endraw %}/{% if deployment_language == 'typescript' %}deploy-config.ts.j2{% endif %} b/template_content/.algokit/generators/create_contract/smart_contracts/{% raw %}{{ contract_name }}{% endraw %}/{% if deployment_language == 'typescript' %}deploy-config.ts.j2{% endif %} index ac114cc..bd3ad2d 100644 --- a/template_content/.algokit/generators/create_contract/smart_contracts/{% raw %}{{ contract_name }}{% endraw %}/{% if deployment_language == 'typescript' %}deploy-config.ts.j2{% endif %} +++ b/template_content/.algokit/generators/create_contract/smart_contracts/{% raw %}{{ contract_name }}{% endraw %}/{% if deployment_language == 'typescript' %}deploy-config.ts.j2{% endif %} @@ -1,5 +1,5 @@ import * as algokit from '@algorandfoundation/algokit-utils' -import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' +import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' // Below is a showcase of various deployment options you can use in TypeScript Client export async function deploy() { @@ -7,27 +7,27 @@ export async function deploy() { const algorand = algokit.AlgorandClient.fromEnvironment() const deployer = await algorand.account.fromEnvironment('DEPLOYER') - - const appClient = algorand.client.getTypedAppClientByCreatorAndName({{ contract_name.split('_')|map('capitalize')|join }}Client, { - sender: deployer, - creatorAddress: deployer.addr, - }) - const app = await appClient.deploy({ - onSchemaBreak: 'append', - onUpdate: 'append', + const factory = algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, { + defaultSender: deployer.addr, }) + const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' }) + // If app was just created fund the app account - if (['create', 'replace'].includes(app.operationPerformed)) { + if (['create', 'replace'].includes(result.operationPerformed)) { await algorand.send.payment({ - amount: algokit.algos(1), + amount: (1).algo(), sender: deployer.addr, receiver: app.appAddress, }) } - const method = 'hello' - const response = await appClient.hello({ name: 'world' }) - console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`) + const method = 'hello' + const response = await appClient.send.hello({ + args: { name: 'world' }, + }) + console.log( + `Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`, + ) } diff --git a/template_content/smart_contracts/{% if deployment_language == 'typescript' %}index.ts{% endif %}.jinja b/template_content/smart_contracts/{% if deployment_language == 'typescript' %}index.ts{% endif %}.jinja index 6955e33..623ca2b 100644 --- a/template_content/smart_contracts/{% if deployment_language == 'typescript' %}index.ts{% endif %}.jinja +++ b/template_content/smart_contracts/{% if deployment_language == 'typescript' %}index.ts{% endif %}.jinja @@ -2,6 +2,7 @@ import * as fs from 'fs' import * as path from 'path' import { consoleLogger } from '@algorandfoundation/algokit-utils/types/logging' import * as algokit from '@algorandfoundation/algokit-utils' +// import { registerDebugEventHandlers } from '@algorandfoundation/algokit-utils-debug' // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger // Uncomment the debug and traceAll options to enable auto generation of AVM Debugger compliant sourceMap and simulation trace file. // Learn more about using AlgoKit AVM Debugger to debug your TEAL source codes and inspect various kinds of Algorand transactions in atomic groups -> https://github.com/algorandfoundation/algokit-avm-vscode-Debugger @@ -11,6 +12,7 @@ algokit.Config.configure({ // debug: true, // traceAll: true, }) +// registerDebugEventHandlers() // Uncomment to enable persisting artifacts required by AlgoKit AVM Debugger // base directory const baseDir = path.resolve(__dirname) diff --git a/template_content/smart_contracts/{{ contract_name }}/{% if deployment_language == 'typescript' %}deploy-config.ts{% endif %}.jinja b/template_content/smart_contracts/{{ contract_name }}/{% if deployment_language == 'typescript' %}deploy-config.ts{% endif %}.jinja index ba3fc68..a375c9f 100644 --- a/template_content/smart_contracts/{{ contract_name }}/{% if deployment_language == 'typescript' %}deploy-config.ts{% endif %}.jinja +++ b/template_content/smart_contracts/{{ contract_name }}/{% if deployment_language == 'typescript' %}deploy-config.ts{% endif %}.jinja @@ -1,5 +1,5 @@ import * as algokit from '@algorandfoundation/algokit-utils' -import { {{ contract_name.split('_')|map('capitalize')|join }}Client } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' +import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' // Below is a showcase of various deployment options you can use in TypeScript Client export async function deploy() { @@ -8,26 +8,26 @@ export async function deploy() { const algorand = algokit.AlgorandClient.fromEnvironment() const deployer = await algorand.account.fromEnvironment('DEPLOYER') - const appClient = algorand.client.getTypedAppClientByCreatorAndName({% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client, { - sender: deployer, - creatorAddress: deployer.addr, + const factory = algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, { + defaultSender: deployer.addr, }) - const app = await appClient.deploy({ - onSchemaBreak: 'append', - onUpdate: 'append', - }) + const { appClient, result } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' }) // If app was just created fund the app account - if (['create', 'replace'].includes(app.operationPerformed)) { + if (['create', 'replace'].includes(result.operationPerformed)) { await algorand.send.payment({ - amount: algokit.algos(1), + amount: (1).algo(), sender: deployer.addr, - receiver: app.appAddress, + receiver: appClient.appAddress, }) } - const method = 'hello' - const response = await appClient.hello({ name: 'world' }) - console.log(`Called ${method} on ${app.name} (${app.appId}) with name = world, received: ${response.return}`) + const method = 'hello' + const response = await appClient.send.hello({ + args: { name: 'world' }, + }) + console.log( + `Called ${method} on ${appClient.appClient.appName} (${appClient.appClient.appId}) with name = world, received: ${response.return}`, + ) } diff --git a/template_content/{% if deployment_language == 'typescript' or use_typescript_jest %}package.json{% endif %}.jinja b/template_content/{% if deployment_language == 'typescript' or use_typescript_jest %}package.json{% endif %}.jinja index 14b0174..87849d6 100644 --- a/template_content/{% if deployment_language == 'typescript' or use_typescript_jest %}package.json{% endif %}.jinja +++ b/template_content/{% if deployment_language == 'typescript' or use_typescript_jest %}package.json{% endif %}.jinja @@ -16,11 +16,12 @@ "npm": ">=9.0" }, "dependencies": { - "@algorandfoundation/algokit-utils": "^6.0.2", + "@algorandfoundation/algokit-utils": "7.0.0-beta.14", + "@algorandfoundation/algokit-utils-debug": "v1.0.2-beta.2", "algosdk": "^2.7.0" }, "devDependencies": { - "@algorandfoundation/algokit-client-generator": "^3.0.3", + "@algorandfoundation/algokit-client-generator": "v4.0.0-beta.5", {%- if use_typescript_jest %} "@types/jest": "^29.5.11", {%- endif %} diff --git a/template_content/{% if use_typescript_jest %}tests{% endif %}/{% if use_typescript_jest %}{% include pathjoin('includes', 'contract_name_kebab.jinja') %}.spec.ts{% endif %}.jinja b/template_content/{% if use_typescript_jest %}tests{% endif %}/{% if use_typescript_jest %}{% include pathjoin('includes', 'contract_name_kebab.jinja') %}.spec.ts{% endif %}.jinja index 5f54543..b7ea209 100644 --- a/template_content/{% if use_typescript_jest %}tests{% endif %}/{% if use_typescript_jest %}{% include pathjoin('includes', 'contract_name_kebab.jinja') %}.spec.ts{% endif %}.jinja +++ b/template_content/{% if use_typescript_jest %}tests{% endif %}/{% if use_typescript_jest %}{% include pathjoin('includes', 'contract_name_kebab.jinja') %}.spec.ts{% endif %}.jinja @@ -1,7 +1,8 @@ import { algorandFixture } from '@algorandfoundation/algokit-utils/testing' -import { {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client } from '../smart_contracts/artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' +import { {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Factory } from '../smart_contracts/artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client' import { Account, Algodv2, Indexer } from 'algosdk' import * as algokit from '@algorandfoundation/algokit-utils' +import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account' describe('{{ contract_name.split('_')|join(' ') }} contract', () => { const localnet = algorandFixture() @@ -13,39 +14,36 @@ describe('{{ contract_name.split('_')|join(' ') }} contract', () => { }) beforeEach(localnet.beforeEach) - const deploy = async (account: Account, algod: Algodv2, indexer: Indexer) => { - const client = new {% include pathjoin('includes', 'contract_name_pascal.jinja') %}Client( - { - resolveBy: 'creatorAndName', - findExistingUsing: indexer, - sender: account, - creatorAddress: account.addr, - }, - algod, - ) - await client.deploy({ - onSchemaBreak: 'append', - onUpdate: 'append', + const deploy = async (account: Account & TransactionSignerAccount) => { + const factory = localnet.algorand.client.getTypedAppFactory({% include pathjoin('includes', 'contract_name_pascal.jinja') %}Factory, { + defaultSender: account.addr, + defaultSigner: account.signer, }) - return { client } + + const { appClient } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' }) + return { client: appClient } } test('says hello', async () => { - const { algod, indexer, testAccount } = localnet.context - const { client } = await deploy(testAccount, algod, indexer) + const { testAccount } = localnet.context + const { client } = await deploy(testAccount) - const result = await client.hello({ name: 'World' }) + const result = await client.send.hello({ args: { name: 'World' } }) expect(result.return).toBe('Hello, World') }) test('simulate says hello with correct budget consumed', async () => { - const { algod, indexer, testAccount } = localnet.context - const { client } = await deploy(testAccount, algod, indexer) - const result = await client.compose().hello({ name: 'World' }).hello({ name: 'Jane' }).simulate() + const { testAccount } = localnet.context + const { client } = await deploy(testAccount) + const result = await client + .newGroup() + .hello({ args: { name: 'World' } }) + .hello({ args: { name: 'Jane' } }) + .simulate() - expect(result.methodResults[0].returnValue).toBe('Hello, World') - expect(result.methodResults[1].returnValue).toBe('Hello, Jane') + expect(result.returns[0]).toBe('Hello, World') + expect(result.returns[1]).toBe('Hello, Jane') expect(result.simulateResponse.txnGroups[0].appBudgetConsumed).toBeLessThan(100) }) })