This commit is contained in:
SaraJane
2025-12-30 13:07:28 +00:00
commit 93e3f09667
95 changed files with 20233 additions and 0 deletions

View File

@ -0,0 +1,15 @@
_tasks:
- "echo '==== Successfully initialized new smart contract 🚀 ===='"
contract_name:
type: str
help: Name of your new contract.
placeholder: "my-new-contract"
default: "my-new-contract"
include_tests:
type: bool
help: Should we include testing files?
default: 'yes'
_templates_suffix: ".j2"

View File

@ -0,0 +1,7 @@
import { Contract } from '@algorandfoundation/algorand-typescript'
export class {{ contract_name.split('_')|map('capitalize')|join }} extends Contract {
{% if preset_name != 'starter' %}public {% endif %}hello(name: string): string {
return `Hello, ${name}`
}
}

View File

@ -0,0 +1,33 @@
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
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() {
console.log('=== Deploying {{ contract_name.split('_')|map('capitalize')|join }} ===')
const algorand = AlgorandClient.fromEnvironment()
const deployer = await algorand.account.fromEnvironment('DEPLOYER')
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(result.operationPerformed)) {
await algorand.send.payment({
amount: (1).algo(),
sender: deployer.addr,
receiver: appClient.appAddress,
})
}
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}`,
)
}

View File

@ -0,0 +1,36 @@
import { Config } from '@algorandfoundation/algokit-utils'
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
import { Address } from 'algosdk'
import { beforeAll, beforeEach, describe, expect, test } from 'vitest'
import { {{ contract_name.split('_')|map('capitalize')|join }}Factory } from '../artifacts/{{ contract_name }}/{{ contract_name.split('_')|map('capitalize')|join }}Client'
describe('{{ contract_name.split('_')|map('capitalize')|join }} contract', () => {
const localnet = algorandFixture()
beforeAll(() => {
Config.configure({
debug: true,
// traceAll: true,
})
})
beforeEach(localnet.newScope)
const deploy = async (account: Address) => {
const factory = localnet.algorand.client.getTypedAppFactory({{ contract_name.split('_')|map('capitalize')|join }}Factory, {
defaultSender: account,
})
const { appClient } = await factory.deploy({ onUpdate: 'append', onSchemaBreak: 'append' })
return { client: appClient }
}
test('says hello', async () => {
const { testAccount } = localnet.context
const { client } = await deploy(testAccount)
const result = await client.send.hello({ args: { name: 'World' } })
expect(result.return).toBe('Hello World')
})
})

View File

@ -0,0 +1,14 @@
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
import { describe, expect, it } from 'vitest'
import { {{ contract_name.split('_')|map('capitalize')|join }} } from './contract.algo'
describe('{{ contract_name.split('_')|map('capitalize')|join }} contract', () => {
const ctx = new TestExecutionContext()
it('Logs the returned value when sayHello is called', () => {
const contract = ctx.contract.create({{ contract_name.split('_')|map('capitalize')|join }})
const result = contract.hello('Sally')
expect(result).toBe('Hello Sally')
})
})