Skip to content

Native android app implementing Ethereum contract for voting. First compose attempts :)

Notifications You must be signed in to change notification settings

alexandr7035/VoteKt

Repository files navigation

README.md

Running Android app

Configure gradle

Add following to gradle.properties:

# Sepolia conig
TESTNET_TEST_MNEMONIC="..."
TESTNET_CONTRACT_ADDRESS="<DEPLOYED_CONTRACT_ADDRESS>"
TESTNET_CHAIN_ID=11155111

INFURA_API_KEY="<INFURA_API_KEY>"
INFURA_NODE_URL="https://sepolia.infura.io"
INFURA_WSS_NODE_URL="wss:https://sepolia.infura.io:443/ws/v3/<INFURA_API_KEY>"

# Hardhat config
LOCAL_CONTRACT_ADDRESS="0x5FbDB2315678afecb367f032d93F642f64180aa3"
LOCAL_TEST_MNEMONIC="test test test test test test test test test test test junk"
LOCAL_CHAIN_ID=31337

LOCAL_NODE_URL="https://10.0.2.2:8545"
LOCAL_WSS_NODE_URL="ws:https://10.0.2.2:8545"

ENABLE_DEMO_NODE=true

If you don't need demo mode, you can leave LOCAL_TEST_MNEMONIC and TESTNET_TEST_MNEMONIC blank.

Run app with local env

  • Run HardHat node locally
mpx hardhat node
npx hardhat compile
npx hardhat --network localhost deploy
  • Choose local* build variant and build the app
  • Use Android Emulator with default network settings

Run app with Sepolia testnet

Create an Infura API key
Choose infura* build variant and build the app.
App will run on Sepolia Testnet

Development

Setup Hardhat environment

# Setup .env file. Use test mnemonic here
# Add Infura API key if you need operate on testnet
MNEMONIC="test test test test test test test test test test test junk"
INFURA_API_KEY="...."

# Run a node
mpx hardhat node

# Deploy contract
# (Sometimes may not compile automatically)
npx hardhat compile
npx hardhat --network localhost deploy

# Create random proposal
npx hardhat --network localhost create_proposal

# Spawn fake votes
npx hardhat --network localhost spawn_votes

# (Optional) Interact from console
npx hardhat --network localhost console

# (Opional) Subscribe to contract events via websockets (replace address with actual)
npx wscat -c https://127.0.0.1:8545/  
>  {"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["logs",{"address":"<CONTRACT_ADDRESS>","topics":[]}]}

Useful materials

Blockchain Series — How MetaMask Creates Accounts

Build your first Android Dapp using Web3j and Infura

Ethereum Unit Converter

Infura Docs

Understanding Ethereum Transaction Statuses

How to use Time in a Smart Contract?

Ethereum RPCs, Methods, and Calls

Subscribing to smart contract events with web3.js

Understanding event logs on the Ethereum blockchain

The Magic of Digital Signatures on Ethereum

Intro to Encoding & Decoding Ethereum Contract Functions

Goerli’s Deprecation: Navigating the Transition to Sepolia
Deprecation Notice for all Infura-Supported Goerli Endpoints

Exploring the Differences Between Payable and Non-Payable Functions in Solidity: An In-Depth Analysis

Why are Encoders used in Solidity?

Are Ethereum Full Nodes Really Full? An Experiment

Explaining Ethereum Contract ABI & EVM Bytecode

Tools

Ethereum Raw Transaction Decoder
Online Ethereum Abi encoder and decoder

Online ABI Encoder
Ethereum input data decoder
How to Set EIP-1559 Gas Fees?

Crypto Logos

Notes

Infura limits (Free):
100,000 Total Requests/Day
25,000 Ethereum Mainnet Archive Requests/Day

DEPRECATED

Compile contract to use via web3j

Install web3j cli tool if not installed

curl -L get.web3j.io | sh && source ~/.web3j/source.sh

Install web3j cli tool if not installed

curl -L get.web3j.io | sh && source ~/.web3j/source.sh

Compile contract with solc and use web3j cli to generate Java class

# Compile
solc --bin --abi contracts/VoteKtV01.sol --base-path '/' --include-path 'node_modules/' -o . --overwrite

# Generate Java wrapper
web3j generate solidity -b VotingContract.bin -a VotingContract.abi -o . -p .

Then copy Java class to project and clean-up.

TODO: Gradle task for web3j

About

Native android app implementing Ethereum contract for voting. First compose attempts :)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages