#typescript smart contracts
11 messages · Page 1 of 1 (latest)
Hi @full knoll. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
I can help you find examples of Algorand TypeScript smart contracts that use box storage.
Algorand TypeScript is a typed language that allows developers to write Algorand smart contracts using TypeScript syntax. It's compatible with standard TypeScript tooling and runs on the Algorand Virtual Machine (AVM).
For box storage in Algorand TypeScript smart contracts, there are several examples and approaches:
- In the unit testing documentation, there's a
BoxStorageContractexample that demonstrates basic box storage operations:
import type { bytes } from '@algorandfoundation/algorand-typescript';
import { arc4, assert, Bytes, op } from '@algorandfoundation/algorand-typescript';
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing';
class BoxStorageContract extends arc4.Contract {
@arc4.abimethod()
storeAndRetrieve(key: bytes, value: bytes): bytes {
op.Box.put(key, value);
const [retrievedValue, exists] = op.Box.get(key);
assert(exists);
return retrievedValue;
}
}
- The state management documentation shows how to define and use boxes in contracts:
class MyContract extends algots.arc4.Contract {
box: algots.Box<algots.uint64> | undefined;
boxMap = algots.BoxMap<algots.bytes, algots.uint64>({ keyPrefix: 'boxMap' });
@algots.arc4.abimethod()
someMethod(keyA: algots.bytes, keyB: algots.bytes, keyC: algots.bytes) {
this.box = algots.Box<algots.uint64>({ key: keyA });
this.box.value = algots.Uint64(1);
this.boxMap.set(keyB, algots.Uint64(1));
this.boxMap.set(keyC, algots.Uint64(2));
}
}
- The client generator documentation shows how to access box storage state through the application client:
// Accessing box storage through the application client
expect(await client.state.box.boxKey()).toBe('baz');
expect(
await client.state.box.boxMap.value({
add: { a: 1n, b: 2n },
subtract: { a: 4n, b: 3n },
}),
).toEqual({
sum: 3n,
difference: 1n,
});
For more comprehensive examples, you might want to explore the examples directory mentioned in the state management documentation, which should contain more detailed implementations of box storage in Algorand TypeScript smart contracts.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@full knoll Kapa.ai is still learning and improving, please let me know how I did by reacting below.
i am looking for github repository where is basic set of smart contract examples
i am looking for github repository where is basic set of smart contract examples
@teal verge i am looking for github repository where is basic set of smart contract examples
Let me check the knowledge base for you again. One moment! :books:
I can help you find GitHub repositories with basic Algorand smart contract examples.
For Algorand TypeScript smart contracts, you can explore these repositories:
-
The Puya TypeScript repository contains the core implementation and examples for Algorand TypeScript:
Algorand TypeScript Repo -
For ARC-12 (Claimable ASA from vault application), there's a reference implementation with contracts and a TypeScript SDK:
ARC-12 Contracts
ARC-12 TypeScript SDK
For Python smart contracts, there's a voting contract example that uses box storage:
Voting Contract Example
You can also explore all Algorand Foundation repositories on GitHub which contain various examples and implementations:
Algorand Foundation GitHub Repositories
These repositories should provide you with a good starting point for understanding and working with Algorand smart contracts, including examples that use box storage as you were previously interested in.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@full knoll Kapa.ai is still learning and improving, please let me know how I did by reacting below.