Getting Started With an Angular dApp Front End

A practical starting point for Angular dApp front ends using signals, the resource API and viem to connect wallets, read state and send transactions.

In this guide
  1. What the stack looks like in late 2026
  2. Create the project and install viem
  3. Set up a public client for reads
  4. Wrap the wallet in a signal-based service
  5. Read on-chain data with resource()
  6. Send a transaction
  7. Project structure and common pitfalls
  8. FAQ
  9. Sources

You can build a production dApp front end with Angular using nothing more than the framework itself and viem, a TypeScript library for talking to EVM chains. Wrap the wallet connection in an injectable service, expose account and chain state as signals, load on-chain reads through Angular's resource() API, and send writes through a viem wallet client. This guide walks through that setup against Angular 22 and viem 2.x.

Most dApp tutorials assume React, but nothing about wallets or JSON-RPC is React-specific. Teams that already ship Angular can follow the blockchain developer roadmap without switching frameworks, and the skills carry over for web developers moving into blockchain.

What the stack looks like in late 2026

The code in this article targets these versions:

Piece Version targeted Why it matters here
Angular 22.x (22.3 is current at the time of writing) Signals, resource() and zoneless change detection are the defaults we build on
TypeScript 6.x Required by Angular 22
Node.js A current LTS release Angular 22 dropped support for Node 20
viem 2.x Typed clients for reads, writes and wallet access

A few Angular facts shape the design:

  • Standalone components are the norm. You do not need NgModules, and you do not need to write standalone: true.
  • Zoneless is the default from Angular 21 onward. Angular no longer patches browser APIs to guess when something changed. The view updates when a signal read in a template changes, when a template event listener runs, or when you call markForCheck().
  • OnPush is the default change detection strategy in Angular 22. Combined with zoneless, this means state that lives outside signals will not refresh the view by itself.
  • resource() is a stable way to bring async data into signal code. It fits contract reads well.

The second and third points are the main trap for dApp code. Wallet events such as accountsChanged arrive from outside Angular. Copy them into a plain class field and the template will not update; copy them into a signal and it will.

Angular moved to one major release per year after version 22, with version 23 targeted for mid-2027.

Create the project and install viem

npm install -g @angular/cli
ng new dapp-frontend
cd dapp-frontend
npm install viem

The CLI asks about styling and server-side rendering. If you enable SSR, remember that window and the wallet do not exist on the server. Keep all wallet access inside methods triggered by user actions (as below) or behind afterNextRender, never in constructors or field initializers.

viem is enough for this guide. The framework-agnostic @wagmi/core package adds connectors and multi-wallet handling on top of it; our wallet integration guide compares the options.

Set up a public client for reads

Reads do not need a wallet. Create one shared public client that talks to an RPC endpoint.

// src/app/web3/clients.ts
import { createPublicClient, http } from 'viem';
import { sepolia } from 'viem/chains';

export const chain = sepolia;

export const publicClient = createPublicClient({
  chain,
  // Pass your own RPC URL here for anything beyond local experiments.
  transport: http(),
});

Calling http() without a URL falls back to the public endpoint bundled with the chain definition. Those endpoints are rate limited, so use a dedicated RPC URL from your provider of choice in real projects, and keep it in Angular's environment configuration.

The example uses the Sepolia testnet. The same code works on other EVM chains, including the rollups covered in Layer 2 explained for developers.

Wrap the wallet in a signal-based service

Browser wallets expose an EIP-1193 provider: an object with a request() method and a small set of events. The service below takes such a provider, builds a viem wallet client around it, and mirrors account and chain state into signals.

// src/app/web3/wallet.service.ts
import { Injectable, computed, signal } from '@angular/core';
import {
  createWalletClient,
  custom,
  type Address,
  type EIP1193Provider,
  type WalletClient,
} from 'viem';
import { chain } from './clients';

@Injectable({ providedIn: 'root' })
export class WalletService {
  private readonly _address = signal<Address | null>(null);
  private readonly _chainId = signal<number | null>(null);
  private client: WalletClient | null = null;

  readonly address = this._address.asReadonly();
  readonly chainId = this._chainId.asReadonly();
  readonly connected = computed(() => this._address() !== null);
  readonly wrongNetwork = computed(
    () => this.connected() && this._chainId() !== chain.id,
  );

  async connect(provider: EIP1193Provider): Promise<void> {
    this.client = createWalletClient({ chain, transport: custom(provider) });

    // Opens the wallet's permission prompt.
    const [address] = await this.client.requestAddresses();
    this._address.set(address ?? null);
    this._chainId.set(await this.client.getChainId());

    provider.on('accountsChanged', (accounts) => {
      this._address.set(accounts[0] ?? null);
    });
    provider.on('chainChanged', (chainIdHex) => {
      this._chainId.set(Number(chainIdHex));
    });
  }

  walletClient(): WalletClient {
    if (!this.client) throw new Error('Wallet not connected');
    return this.client;
  }
}

Points worth noticing:

  • The writable signals are private. Components get read-only views through asReadonly(), so only the service can change wallet state.
  • chainChanged delivers the chain ID as a hexadecimal string, so it is converted with Number().
  • An empty accountsChanged array means the user disconnected or locked the wallet. The service treats that as "not connected".

Where the provider comes from

The simplest source is the legacy window.ethereum global:

import type { EIP1193Provider } from 'viem';

export function injectedProvider(): EIP1193Provider | undefined {
  return (window as Window & { ethereum?: EIP1193Provider }).ethereum;
}

That is fine for a first prototype, but it breaks down when a user has several wallet extensions installed, because they compete for the same global. The current standard, EIP-6963, lets each wallet announce itself through browser events so you can show a proper wallet picker. The wallet integration guide linked above includes a working discovery snippet that plugs straight into WalletService.connect().

Read on-chain data with resource()

resource() takes a reactive params function and an async loader. Whenever a signal read inside params changes, the loader runs again. If params returns undefined, the loader does not run and the resource sits in the idle state. That maps neatly onto "only fetch a balance when an account is connected".

// src/app/account-panel.component.ts
import { Component, inject, resource } from '@angular/core';
import { formatEther } from 'viem';
import { publicClient } from './web3/clients';
import { injectedProvider, WalletService } from './web3/wallet.service';

@Component({
  selector: 'app-account-panel',
  template: `
    @if (wallet.connected()) {
      <p>Account: {{ wallet.address() }}</p>

      @if (wallet.wrongNetwork()) {
        <p role="alert">Please switch your wallet to Sepolia.</p>
      }

      @if (balance.hasValue()) {
        <p>Balance: {{ format(balance.value()) }} ETH</p>
      } @else if (balance.isLoading()) {
        <p>Loading balance...</p>
      } @else if (balance.error()) {
        <p role="alert">Could not load the balance.</p>
      }

      <button type="button" (click)="balance.reload()">Refresh</button>
    } @else {
      <button type="button" (click)="connect()">Connect wallet</button>
    }
  `,
})
export class AccountPanelComponent {
  protected readonly wallet = inject(WalletService);

  protected readonly balance = resource({
    params: () => this.wallet.address() ?? undefined,
    loader: ({ params: address }) => publicClient.getBalance({ address }),
  });

  protected format(wei: bigint): string {
    return formatEther(wei);
  }

  protected async connect(): Promise<void> {
    const provider = injectedProvider();
    if (!provider) {
      alert('No browser wallet found.');
      return;
    }
    await this.wallet.connect(provider);
  }
}

Here injectedProvider is assumed to be exported from the service file.

Check hasValue() before reading value(). Reading the value of a resource that is in the error state throws, and hasValue() also narrows the type so the template knows it is dealing with a bigint.

viem returns token amounts as bigint. Never convert them to number for display, because values above 2^53 lose precision. Use formatEther or formatUnits, which return strings.

Contract reads follow the same pattern. Swap getBalance for publicClient.readContract({ address, abi, functionName, args }) inside the loader. When the ABI is declared with as const or built with parseAbi, viem infers argument and return types from it.

Send a transaction

Writes go through the wallet client, because the wallet holds the key and must show a confirmation prompt. viem's documentation recommends simulating the call first with the public client, then passing the prepared request to writeContract. Simulation catches reverts before the user pays for gas.

// src/app/web3/counter.service.ts
import { Injectable, inject, signal } from '@angular/core';
import { parseAbi, type Address, type Hash } from 'viem';
import { publicClient } from './clients';
import { WalletService } from './wallet.service';

const counterAbi = parseAbi([
  'function number() view returns (uint256)',
  'function increment()',
]);

// Replace with your deployed contract address.
const COUNTER_ADDRESS: Address = '0x0000000000000000000000000000000000000000';

type TxState = 'idle' | 'awaiting-signature' | 'pending' | 'confirmed' | 'failed';

@Injectable({ providedIn: 'root' })
export class CounterService {
  private readonly wallet = inject(WalletService);
  readonly txState = signal<TxState>('idle');
  readonly lastHash = signal<Hash | null>(null);

  async increment(): Promise<void> {
    const account = this.wallet.address();
    if (!account) throw new Error('Wallet not connected');

    try {
      this.txState.set('awaiting-signature');
      const { request } = await publicClient.simulateContract({
        account,
        address: COUNTER_ADDRESS,
        abi: counterAbi,
        functionName: 'increment',
      });
      const hash = await this.wallet.walletClient().writeContract(request);
      this.lastHash.set(hash);

      this.txState.set('pending');
      const receipt = await publicClient.waitForTransactionReceipt({ hash });
      this.txState.set(receipt.status === 'success' ? 'confirmed' : 'failed');
    } catch {
      this.txState.set('failed');
    }
  }
}

Users need to see each phase of a transaction: waiting for the wallet prompt, submitted, confirmed, failed. Modelling that as a signal keeps templates simple. After a confirmed write, call reload() on any resource that depends on the changed state.

In a real app, separate "user rejected the request" from other failures rather than collapsing everything into failed. The wallet integration guide covers the standard error codes.

Project structure and common pitfalls

Keep chain definitions and clients in one file, connection state in the wallet service, and one service per contract that owns its ABI, address and write methods. Components then only read signals and call service methods.

Pitfalls that come up repeatedly:

  • State outside signals. With zoneless change detection and OnPush, a value assigned from a wallet event callback into a plain field will not re-render. Always write to a signal.
  • Polling too eagerly. A dashboard that calls readContract for dozens of values on every block will hit RPC rate limits. For lists and history, query an indexer or your own database instead; see indexing blockchain data and off-chain data with PostgreSQL.
  • Trusting the front end. Anything enforced only in the UI can be bypassed by calling the contract directly. Access rules belong in the contract, as explained in smart contract security basics.

FAQ

Do I need wagmi to build an Angular dApp?

No. viem alone covers reads, writes and wallet access, as shown above. @wagmi/core is framework-agnostic and adds connectors, reconnection and multi-wallet state, so it becomes attractive once you support several wallet types. The React hooks package is not usable in Angular.

Can I use ethers.js instead of viem?

Yes. The service pattern is identical with ethers v6: wrap BrowserProvider and its signer in a service and publish state through signals. viem is used here for its ABI-driven type inference.

Do I still need RxJS?

Not for this use case. Signals and resource() handle wallet state and one-shot reads. RxJS remains useful for continuous streams.

Sources

About the author

Alessandro Moretti is a crypto analyst and blockchain strategist who writes and maintains the guides on BlockDev Path. Every factual claim is checked against the primary sources listed above. Spotted an error? Tell us and we will correct it. See our editorial policy.