Skip to content

Instantly share code, notes, and snippets.

@0M3REXE
Created February 6, 2025 15:44
Show Gist options
  • Save 0M3REXE/87216d598047c67079df8e0ccf24d1ac to your computer and use it in GitHub Desktop.
Save 0M3REXE/87216d598047c67079df8e0ccf24d1ac to your computer and use it in GitHub Desktop.
from algopy import ARC4Contract, UInt64
from algopy.arc4 import abimethod
class Calculator(ARC4Contract):
@abimethod()
def add(self,a:UInt64,b:UInt64)->UInt64:
return a+b
@abimethod()
def sub(self,a:UInt64,b:UInt64)->UInt64:
return a-b
@abimethod()
def mul(self,a:UInt64,b:UInt64)->UInt64:
return a*b
@abimethod()
def div(self,a:UInt64,b:UInt64)->UInt64:
return a//b
@0M3REXE
Copy link
Author

0M3REXE commented Feb 6, 2025

import logging

import algokit_utils
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient

logger = logging.getLogger(__name__)


# define deployment behaviour based on supplied app spec
def deploy(
    algod_client: AlgodClient,
    indexer_client: IndexerClient,
    app_spec: algokit_utils.ApplicationSpecification,
    deployer: algokit_utils.Account,
) -> None:
    from smart_contracts.artifacts.calculator.calculator_client import (
        CalculatorClient,
    )
    testnetAlgodClient = AlgodClient("a"*64,"https://testnet-api.algonode.cloud")
    testnetIndexerClient = IndexerClient("a"*64,"https://testnet-idx.algonode.cloud")
    myAccount = algokit_utils.get_account_from_mnemonic("black tail ozone secret much theory urge heavy cake clog diesel glass zebra novel soul scrub holiday oil reunion year tissue certain surge absorb mother")


    '''app_client = CalculatorClient(
        algod_client,
        creator=deployer,
        indexer_client=indexer_client,
    )'''
    app_client = CalculatorClient(
        algod_client=testnetAlgodClient,
        creator=myAccount,
        indexer_client=testnetIndexerClient,
    )

    app_client.deploy(
        on_schema_break=algokit_utils.OnSchemaBreak.AppendApp,
        on_update=algokit_utils.OnUpdate.AppendApp,
    )
    
    logger.info(f"Deployed Calculator with App ID: {app_client.app_id}")
    a=10
    b=5
    response = app_client.add(a=a, b=b)
    logger.info(
        f"Called add on {app_spec.contract.name} ({app_client.app_id}) "
        f"with a={a} and  b={b} received: {response.return_value}"
    )
    a=20
    b=5
    response = app_client.sub(a=a, b=b)
    logger.info(
        f"Called add on {app_spec.contract.name} ({app_client.app_id}) "
        f"with a={a} and  b={b} received: {response.return_value}"
    )
    a=10
    b=5
    response = app_client.mul(a=a, b=b)
    logger.info(
        f"Called add on {app_spec.contract.name} ({app_client.app_id}) "
        f"with a={a} and  b={b} received: {response.return_value}"
    )
    a=10
    b=5
    response = app_client.div(a=a, b=b)
    logger.info(
        f"Called add on {app_spec.contract.name} ({app_client.app_id}) "
        f"with a={a} and  b={b} received: {response.return_value}"
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment