Ethereum & Solidity

Chapter 9
Decentralized Application Integration

Diploma in Blockchain
Ethereum & Solidity   •   Diploma

Decentralized Application Integration

Introduction

A decentralized application (dApp) is not merely a web page with a smart contract behind it. It is an integrated system in which user interfaces, wallets, blockchain nodes, smart contracts, decentralized storage, indexing systems, and sometimes external data services cooperate under explicit trust assumptions. The quality of this integration determines whether an application is secure, usable, observable, and maintainable.

A typical dApp has two broad execution environments. The off-chain environment includes the browser or mobile application, backend services, databases, indexing systems, and decentralized storage. The on-chain environment includes Ethereum contracts, transaction execution, consensus, and event logs. The boundary between these environments must be designed carefully: anything enforced by a contract can be independently verified on Ethereum, whereas interface logic and ordinary server logic may be changed, censored, or compromised.

This chapter explains how to connect web and mobile interfaces to Ethereum contracts, manage wallets and signatures, use ABI-based interactions and events, integrate decentralized storage and indexing services, and evaluate oracles and off-chain services without overstating their trustlessness.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Describe the architecture of a complete Ethereum dApp.
  2. Distinguish read operations, simulated transactions, and state-changing transactions.
  3. Connect browser and mobile wallets using appropriate provider interfaces.
  4. Explain ABI encoding, contract calls, transaction signing, confirmations, and events.
  5. Design practical integrations with decentralized storage, indexers, oracles, and backend services.
  6. Identify security, privacy, reliability, governance, and regulatory risks.
  7. State the trust assumptions of an integrated dApp clearly.

1. The dApp Integration Architecture

The principal components of a dApp are shown conceptually below.

Architecture of a decentralized application Web / Mobile UIwallet provider Ethereum ClientRPC, ABI, signer Smart Contractsstate and events Storage / Indexercontent and queries Oracle / Backendexternal information Ethereum Networknodes and consensus
Architecture of a decentralized application
Figure: Architecture of a decentralized application

Figure: Main components and information boundaries in a dApp.

The interface presents data and requests actions. An Ethereum client library translates application-level requests into JSON-RPC calls and transaction objects. A provider supplies read access to a blockchain node; a signer authorizes transactions using a private key held by a wallet. The contract address and ABI identify the deployed program and describe how its functions and events are encoded.

The architecture is hybrid by necessity. Ethereum provides durable shared state and verifiable execution, but it is not normally suitable for large files, full-text search, high-frequency user-interface queries, or private business information. Such requirements are handled off-chain, with the resulting trust and availability consequences documented.

2. Providers, Signers, and Wallet Connections

A provider is an interface for querying a chain: reading account balances, retrieving blocks, estimating gas, obtaining transaction receipts, and calling read-only contract functions. A signer is an account capable of authorizing a state-changing transaction. In browser applications, the signer is usually exposed by a wallet such as MetaMask or another wallet implementing a wallet-provider standard.

A safe connection flow is:

  1. Detect whether a compatible wallet provider exists.
  2. Request access explicitly; never assume that an account is available.
  3. Read the selected chain identifier and compare it with the application’s supported networks.
  4. Create a provider and signer through the client library.
  5. Listen for account and network changes.
  6. Clear cached account-specific data when the user disconnects or changes accounts.
  7. Require the wallet to display and approve every signature or transaction.

The application should not request a private key. A private key entered into an ordinary website can be copied and is no longer protected by the wallet. Mobile applications may use wallet connection protocols or embedded wallets, but the same principle applies: key custody and signing authority must be explicit.

A chain identifier prevents an application from silently using the wrong network. The interface should show whether it is connected to mainnet, a test network, or a local development chain. Contract addresses must be network-specific; deploying a contract on one network does not make it available at the same address on another network.

Provider and signer roles

OperationProvider requiredSigner requiredChanges blockchain state?
Read contract stateYesNoNo
Estimate gasYesUsually noNo
Simulate a transactionYesSometimesNo
Submit a transactionYesYesYes, if mined
Read an event logYesNoNo
Sign a messageNo node access strictly requiredYesNo

A signed message is not the same as a transaction. A message signature proves control of a key for a specified message, but it does not itself execute contract code or alter blockchain state. Applications must use domain separation, clear human-readable messages, nonces, expiration times, and the intended contract or service identity to reduce replay and phishing risks.

3. ABI-Based Contract Interaction

The Application Binary Interface (ABI) specifies how function calls, return values, errors, and events are encoded. A contract instance in a client library is normally constructed from three items: a provider or signer, a deployed address, and the ABI.

For a read-only function, the library encodes the function selector and arguments, sends an eth_call, and decodes the result. This operation is evaluated by a node against a selected blockchain state and does not create a transaction. A state-changing function instead produces a transaction request. The wallet displays the request, signs it, and sends it to the network.

A robust transaction workflow is:

  1. Validate user input locally.
  2. Confirm the target chain and contract address.
  3. Encode the function call from the ABI.
  4. Estimate gas and identify likely reverts.
  5. Present destination, value, and a meaningful description to the user.
  6. Obtain wallet approval.
  7. Submit the signed transaction.
  8. Display the transaction hash immediately.
  9. Wait for a receipt and communicate pending, confirmed, or failed status.
  10. Refresh state from the chain rather than trusting a local optimistic update indefinitely.

Gas estimation is not a guarantee of success. State can change between estimation and mining, a transaction can use a different execution path, or a contract can deliberately revert under a later condition. A user interface should therefore handle rejected signatures, insufficient funds, underpriced or replaced transactions, network errors, and contract reverts.

ABI and data representation

Solidity types require careful conversion at the interface boundary. Ether-denominated values should be represented with arbitrary-precision integer utilities rather than JavaScript floating-point numbers. For an integer amount expressed in the smallest unit, a display value can be computed as:

d = n ÷ 10k

Here, n is the integer quantity in the smallest unit, k is the number of decimal places, and d is a display quantity. The formula is a representation conversion, not permission to use imprecise floating-point arithmetic for financial calculations. Ethereum’s native currency uses 18 decimal places, while an ERC-20 token may define a different decimal count. Token decimals affect presentation, not the token’s underlying integer storage.

The interface must also handle addresses, bytes values, arrays, tuples, signed and unsigned integers, and custom errors. User-supplied values should be validated before encoding, but contract validation remains authoritative.

4. Events, Logs, and Application State

Solidity events create transaction logs that are useful for indexing and user-interface updates. An event may contain indexed parameters, which are efficient for filtering, and non-indexed parameters, which are stored in the log data. Events are not ordinary contract storage: contracts cannot generally query their historical logs during execution, and an event should not be treated as the sole source of a critical state value.

For example, a token contract may emit a transfer event after updating balances. An indexer can consume the event and build a searchable representation. The interface can subscribe to new events for responsive updates, but it should also reconcile with confirmed chain state because subscriptions can disconnect, providers can lag, and reorganizations can temporarily change the canonical history.

A useful event-handling policy distinguishes:

  • Pending: a transaction has been submitted but is not confirmed.
  • Confirmed: a receipt has been obtained on the observed chain.
  • Finalized or sufficiently settled: the application’s policy considers reorganization risk acceptably low.
  • Reverted: execution failed, so the intended state transition did not occur.

The required number of confirmations depends on value, chain characteristics, and risk tolerance. It is an application policy, not a universal constant. High-value settlement should not rely solely on a browser event listener.

5. Decentralized Storage

Blockchain storage is expensive and constrained. Large assets such as images, documents, metadata, and media are commonly stored in systems such as IPFS or other content-addressed networks. A content identifier is derived from content, so changing the content normally produces a different identifier. The contract can store this identifier or a reference to it.

This design separates integrity from availability. A content identifier helps verify that retrieved bytes correspond to the referenced content, but it does not guarantee that somebody will continue providing those bytes. Pinning, replication, gateways, archival services, or a decentralized storage market may be needed for availability.

A sound upload workflow is:

  1. Validate file type, size, and user permissions.
  2. Remove unintended sensitive metadata.
  3. Encrypt confidential content before uploading when appropriate.
  4. Upload and obtain a content identifier.
  5. Verify retrieval and content integrity.
  6. Store the identifier, not the large file, in the contract where on-chain reference is required.
  7. Consider immutable metadata, replacement procedures, and legal takedown obligations.

Content addressing does not make content private. If a file is public and unencrypted, anyone who obtains its identifier may retrieve it. Likewise, putting a pointer on a public blockchain can permanently expose relationships between users and content.

6. Indexing and Query Services

Ethereum nodes are excellent at authoritative state queries but are not optimized for arbitrary application queries such as “show all items owned by this user, sorted by date, with metadata.” Indexing services consume blocks and events, transform them into queryable stores, and expose APIs such as GraphQL or REST.

An indexer improves performance and usability but introduces dependencies. It may be delayed, misconfigured, unavailable, or controlled by one provider. The application should record the indexed block height, handle pagination, and provide a strategy for detecting or recovering from missed events. For high-assurance operations, critical values should be checked against the chain or an independently operated indexer.

A common pattern is event sourcing: contract events form the input stream, and the indexer maintains a derived view. The derived view is not authoritative merely because it is convenient. Reorganizations, contract upgrades, event omissions, and indexing bugs must be considered. Indexers should process events idempotently, meaning that replaying the same event does not create unintended duplicate effects.

7. Oracles and Off-Chain Services

A smart contract cannot directly fetch an arbitrary web page, query a private database, or observe a physical sensor. An oracle supplies external data or triggers based on information outside the blockchain. Examples include asset prices, weather readings, sports results, identity attestations, and cross-chain messages.

The central question is not whether an oracle is called “decentralized,” but what trust assumptions it provides. Relevant dimensions include:

  • number and independence of data sources;
  • method for aggregating conflicting reports;
  • update frequency and latency;
  • resistance to manipulation;
  • signer and key-management arrangements;
  • failure, dispute, and emergency procedures;
  • incentives and accountability of operators.

A price-feed consumer should define freshness limits and reject stale data. It should also consider unusual values, decimal conventions, round identifiers, and the possibility that a feed becomes unavailable. Financial contracts often use multiple safeguards such as collateralization, circuit breakers, time-weighted prices, and governance-controlled pause mechanisms.

A centralized backend can be entirely appropriate for notifications, search, analytics, or privacy-preserving workflows, provided that its role is transparent. It becomes misleading when the interface presents a centrally controlled result as if it were enforced by Ethereum. The architecture should state which claims are guaranteed by the contract and which depend on an operator.

8. Security and Trust Boundaries

Integration expands the attack surface beyond Solidity. Common interface threats include malicious contract addresses, phishing pages, deceptive transaction descriptions, cross-site scripting, compromised dependencies, incorrect chain selection, signature replay, leaked API credentials, and denial of service through a single RPC endpoint.

Important controls include:

  • verify deployed bytecode, ABI, and addresses through an independent release process;
  • use checksummed addresses and network-specific configuration;
  • display the actual recipient, value, and function purpose;
  • avoid blind signing where possible;
  • use typed structured data for authorization messages;
  • bind signatures to a domain, chain, contract, purpose, nonce, and expiry;
  • never place private keys or privileged secrets in client-side code;
  • validate all data received from indexers and APIs;
  • use multiple RPC providers or a fallback strategy;
  • apply content security policy and dependency controls;
  • monitor contracts, transactions, events, and abnormal user activity;
  • design recovery procedures for compromised interfaces.

The security of a dApp is bounded by its weakest trust boundary. A mathematically correct contract cannot protect users who are tricked into signing a malicious transaction, and a reliable wallet cannot correct an application configured with the wrong contract address.

9. Applied Case: Illustrative Community Grant dApp

Background

Consider an illustrative community grant application. Members submit proposals, vote using an ERC-20 governance token, and receive funds if a proposal passes. Proposal descriptions and evidence may include documents and images.

Problem

The organization wants transparent voting and payment records but needs searchable proposal pages, manageable documents, notifications, and a mobile-friendly interface. It must also clarify what remains dependent on service operators.

Analysis

The contract should enforce proposal eligibility, voting periods, quorum rules, vote accounting, execution authorization, and payment limits. It should emit events for proposal creation, voting, and execution. Large documents should not be stored on-chain. An indexer is useful for proposal search, while a backend can send notifications. However, the indexer and notification service must not be able to alter votes or authorize payments.

Approach and solution

The web and mobile clients connect to wallets and check the chain identifier before creating a contract instance. Read-only proposal data comes from an indexer for speed, with important totals checked against contract calls. A proposal submission first uploads sanitized documents to content-addressed storage; the resulting identifier is included in the on-chain proposal transaction.

Before a vote, the interface displays the proposal identifier, voting deadline, token amount, and destination contract. The wallet signs the transaction. After submission, the interface shows the hash and waits for a receipt. The indexer updates its derived view from emitted events, while a reconciliation task compares indexed block heights and selected records with node queries.

The contract does not trust the notification backend. It also does not treat an uploaded document as approved merely because it is available. Moderation status is represented by an explicit governance action or separate signed attestation, depending on the organization’s policy.

Outcome

The design provides transparent on-chain voting and execution while using off-chain systems for practical user experience. Users can verify the contract rules and transaction history, but they must trust storage providers for availability, the indexer for timely search results, and the interface for accurately presenting transactions. Those dependencies are documented rather than hidden.

Learning points

  1. Put enforcement, not merely display, in the contract.
  2. Treat indexer data as a derived view.
  3. Distinguish content integrity from content availability.
  4. Make wallet prompts and trust assumptions understandable.
  5. Provide fallback verification for high-value actions.

10. Testing, Operations, and Professional Practice

Integration testing should cover wallet connection, unsupported networks, account changes, rejected signatures, insufficient funds, reverted calls, delayed confirmations, dropped transactions, replacement transactions, provider failure, stale indexer data, unavailable storage, and malformed external data.

A practical test sequence includes unit tests for encoding and display conversion; contract tests for state transitions and events; integration tests against a local chain or test network; end-to-end tests using a controlled wallet; and adversarial tests for incorrect addresses, replayed signatures, stale oracle data, and manipulated API responses.

Operational observability should include transaction hashes, contract addresses, chain identifiers, block numbers, event-processing status, RPC latency, and error categories. Logs must not expose private keys, seed phrases, authentication tokens, or unnecessary personal data.

Upgrades require special care. If a contract is upgradeable, users must understand who controls upgrade authority, how upgrades are announced, whether storage layout is preserved, and what emergency powers exist. A supposedly immutable contract may still depend on upgradeable tokens, oracles, frontends, and storage gateways. Governance is therefore part of technical architecture.

11. Limitations, Ethics, and Regulation

Blockchain integration can improve auditability, but it does not automatically produce truthful input, fair governance, or equal access. Users may face gas costs, wallet complexity, irreversible mistakes, accessibility barriers, and privacy exposure. Public transaction histories can enable profiling. A dApp serving real communities should minimize personal data, provide understandable consent, support recovery where feasible, and avoid coercive signing flows.

Legal obligations may apply to token sales, financial services, consumer protection, data protection, digital identity, sanctions compliance, intellectual property, and gambling. Immutability can conflict with correction or deletion requirements. The appropriate response is not to assume that blockchain overrides law; it is to design data minimization, off-chain redaction strategies, governance controls, and professional compliance review.

Artificial intelligence may assist with interface support, anomaly detection, code review, or search, but an AI service is another off-chain trust dependency. AI-generated transaction explanations must be checked against the actual calldata and contract ABI. An AI assistant should never be given uncontrolled signing authority merely because it can describe a transaction.

12. Best-Practice Checklist

Before releasing an integrated dApp, confirm that:

  • supported chains and contract addresses are explicit;
  • ABI files and deployed bytecode are version-controlled;
  • provider and signer roles are separated;
  • no private key is requested by the interface;
  • transaction details are understandable before approval;
  • signatures include domain, nonce, purpose, and expiry where applicable;
  • receipts, reverts, replacements, and reorganizations are handled;
  • event processing is replay-safe and monitored;
  • indexer data can be reconciled with chain data;
  • storage integrity and availability assumptions are documented;
  • oracle freshness and failure behavior are defined;
  • external services cannot bypass contract authorization;
  • privacy, accessibility, governance, and regulatory risks are reviewed.

Chapter Summary

Decentralized application integration connects user interfaces and wallets to Ethereum contracts through providers, signers, ABI encoders, transaction workflows, and event systems. Read calls do not change state, while state-changing actions require wallet authorization and later confirmation. Events support responsive interfaces and indexing but are not a replacement for authoritative contract state.

Decentralized storage is useful for large content, although content integrity does not guarantee availability or privacy. Indexers provide efficient derived views but introduce availability, correctness, and reorganization risks. Oracles and backends extend functionality beyond Ethereum while adding explicit trust assumptions. Secure integration therefore requires clear network and address configuration, safe message signing, robust error handling, reconciliation, monitoring, privacy protection, and transparent governance. The professional objective is not to eliminate every off-chain dependency, but to identify each dependency and ensure that critical guarantees remain enforceable and verifiable.

Key Terms

Provider: A client interface used to query an Ethereum network.

Signer: An account interface capable of authorizing signatures or transactions.

Wallet: Software or hardware that manages keys and approves signatures.

ABI: The specification for encoding and decoding contract functions, errors, and events.

RPC: A protocol and interface through which applications communicate with blockchain nodes.

Contract instance: A client-side object binding an ABI and address to a provider or signer.

Transaction: A signed request that may change blockchain state.

Receipt: A record reporting the mined execution result of a transaction.

Event: A Solidity-emitted log intended for off-chain observation and indexing.

Indexer: A service that transforms blockchain data into queryable derived views.

Content addressing: Identifying data by a value derived from its content.

IPFS: A peer-to-peer, content-addressed system commonly used for decentralized distribution.

Oracle: A mechanism that supplies external information to a smart contract.

Nonce: A value used to order account transactions or prevent signature replay.

Chain identifier: A network identifier used to distinguish Ethereum environments.

Reorganization: A change in the temporarily observed chain history.

Finality: The point or policy at which reversal risk is considered acceptably low.

Trust assumption: A dependency on an actor, service, data source, or governance process.

Gas estimation: A prediction of execution gas required by a transaction.

Derived view: Data reconstructed from authoritative records, commonly events and state.

Review Questions

5 Short Answer Questions

  1. What is the difference between a provider and a signer?
  2. Why should a dApp verify the selected chain identifier?
  3. Why are events useful to indexers?
  4. What does content addressing provide, and what does it not guarantee?
  5. Why is a signed message not equivalent to a blockchain transaction?

5 Long Answer Questions

  1. Explain the complete lifecycle of a state-changing contract interaction, from user input to confirmed receipt.
  2. Discuss the advantages and limitations of using an indexing service for a dApp interface.
  3. Explain the main trust assumptions introduced by oracles and off-chain backends.
  4. Describe a secure wallet-connection design for a mobile or browser application.
  5. Discuss how privacy, accessibility, and governance concerns affect dApp integration.

3 Analytical / Application Questions

  1. A dApp displays a successful transfer from its indexer, but a direct node query shows that the transaction reverted. Diagnose possible causes and propose a reconciliation policy.
  2. Design the storage and contract-reference architecture for a dApp handling confidential documents. Identify integrity, availability, privacy, and legal risks.
  3. An application uses a single price oracle and a centralized frontend controlled by one company. Evaluate its decentralization claim and recommend technical and governance improvements.

Multiple Choice Questions with Answers

Question 1

Which component normally authorizes a state-changing Ethereum transaction?

A. A signer or wallet

B. An event log

C. An indexer

D. A content identifier

Correct Answer: A. A signer or wallet

Question 2

What does an ABI primarily specify?

A. How blockchain consensus is reached

B. How contract calls, results, errors, and events are encoded

C. How private keys are generated

D. How files are pinned on storage networks

Correct Answer: B. How contract calls, results, errors, and events are encoded

Question 3

Which statement about an eth_call read operation is correct?

A. It always requires a wallet signature

B. It changes contract storage immediately

C. It evaluates contract code without creating a state-changing transaction

D. It can only read event logs

Correct Answer: C. It evaluates contract code without creating a state-changing transaction

Question 4

What is a major limitation of a content identifier in decentralized storage?

A. It guarantees that a file is private

B. It guarantees permanent availability from providers

C. It prevents the content from being changed anywhere

D. It helps verify content identity but does not by itself guarantee availability

Correct Answer: D. It helps verify content identity but does not by itself guarantee availability

Question 5

Why should an application reconcile indexer data with blockchain data?

A. Indexers are authoritative replacements for contracts

B. Indexers can be delayed, incorrect, or affected by missed events and reorganizations

C. Blockchain nodes cannot return transaction receipts

D. Events cannot be read by any off-chain service

Correct Answer: B. Indexers can be delayed, incorrect, or affected by missed events and reorganizations

Question 6

Which practice best reduces replay risk for signed application messages?

A. Removing all timestamps and identifiers

B. Using a domain, nonce, purpose, and expiration

C. Storing the private key in the browser

D. Signing the same message repeatedly

Correct Answer: B. Using a domain, nonce, purpose, and expiration

Question 7

What does an oracle provide to a smart contract?

A. A private key for the contract owner

B. External information or triggers from outside the blockchain

C. Automatic encryption of all user files

D. A replacement for transaction receipts

Correct Answer: B. External information or triggers from outside the blockchain

Question 8

Why must an interface handle a transaction receipt rather than only showing a transaction hash?

A. A hash proves that execution succeeded

B. A receipt reports whether the submitted transaction was mined and how it executed

C. Receipts contain the user’s private key

D. A hash cannot identify a transaction

Correct Answer: B. A receipt reports whether the submitted transaction was mined and how it executed

Question 9

Which statement about a centralized backend is most accurate?

A. Its use automatically makes a dApp decentralized

B. It can be used, but its control and failure assumptions should be disclosed

C. It can override contract authorization if it is trusted

D. It cannot provide notifications or search

Correct Answer: B. It can be used, but its control and failure assumptions should be disclosed

Question 10

Why should an application avoid JavaScript floating-point arithmetic for token amounts?

A. Floating point always increases gas costs

B. Token balances are stored as exact integers and floating point can lose precision

C. Wallets reject all decimal values

D. ABI encoding supports only strings

Correct Answer: B. Token balances are stored as exact integers and floating point can lose precision

Ethereum & Solidity
Chapter 9 of 15