Coder Social home page Coder Social logo

algorandpayrollcontract's Introduction

Algorand Android Payroll Smart Contract using the Java SDK

This solution will guide you in developing and deploying android application using the Algorand blockchain atomic transfer and smart contract that addresses the following use case:

  • Account creation

  • Funding accounts

  • Create and compile the teal program

  • Atomic transfer signed by the sender

  • Atomic transfer signed by a smart contract

Demo

BACKIMAGE

Requirements

  • Android studio setup

  • Familiarity with the Java and Kotlin programming language and its use within the Android Environment.

  • Basic understanding of some blockchain terminologies.

  • Basic understanding of teal and stateless smart contract

Tools/ Libraries used

Below are some of the important libraries used:

  • Algorand SDK
  • Coroutines
  • Glide
  • Databinding

Setup Development Environment

To get started, your android studio should be up and running. To get the code on your android studio, simply click the clone button to clone the project or download the the project. Then from Android studio click on file and select import to import the project from your local machine.

To successfully run this program, you need to generate/create four different accouts one for the contract owner and the remaining three for the employees. You can create accounts using myalgo.

App Installation Guide

To install the app, here is the link to the apk

File Structure

  • EmployeeAdapter handles the recyclerview for the list of employees
  • constants handles constant variables used in the MainActivity and DetailActivity
  • MainActivity handles the main logic of the application
  • DetailActivity handles the detail page for each employees
  • Employee handles the data model
  • EmployeeDataSource handles dummy data/list of empployees

Teal Program/Smart Contract

 val tealSource = """#pragma version 5        
                // Check the Fee is resonable, In this case 1,000 microalgos
                txn Fee
                int 1000
                <=

                //Check that the first group transaction is equal to 2000000
                gtxn 0 Amount
                int 2000000
                ==
                assert
                
                //Check that the second group transaction is equal to 1000000
                gtxn 1 Amount
                int 1000000
                == 
                assert
               
                //Check that the third group transaction is equal to 2000000
                gtxn 2 Amount
                int 2000000
                ==
                assert
                
                //Check that the transaction amount is less than 5000000 or equal to 5000000
                txn Amount
                int 5000000
                <=
                assert
                
                //Check the number of transactions in this atomic transaction group
                global GroupSize
                int 3
                ==
                assert
                
                //CloseRemainderTo should be the intended recipient or equal to global ZeroAddress.
                txn CloseRemainderTo 
                global ZeroAddress
                ==
                assert
                
                //This check to prevent the transaction from been assigned to a new private key.
                txn RekeyTo
                global ZeroAddress
                ==
                assert     
            """.trimIndent()

How the app works

After installation..

  • It takes you to the MainActivity. The MainActivity contains a list of employees, two fabs and two buttons
  • The green fab enables you to fund the contract/senders account
  • The purple fab enables you to copy the contract/senders address
  • The explore button takes you to the algoexplorer page
  • The pay employees button calls the atomic transfer method to send algo to the employees either using the smart contract logic sig option or the sender option

License

Distributed under the MIT License. See for more information. LICENSE

Blog and Video Tutorial

For more details you can checkout the blog post here . And here is the link to the youtube demo

Disclaimer

This project is not audited and should not be used in a production environment.

algorandpayrollcontract's People

Contributors

gconnect avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.