# DApp Design Patterns

{% hint style="danger" %}
**Outdated Documentation:** This page covers the architecture used for USC V1, which was deprecated on 2026-03-30. For the latest documentation, please visit: [usc documentation](https://docs.creditcoin.org/usc)
{% endhint %}

## Creditcoin Oracle Design Patterns

> *How you* **can** *use the Creditcoin Oracle vs how you* **should**.

Cross-chain DApps use [Universal Smart Contracts](/usc/usc-v1/dapp-builder-infrastructure/universal-smart-contracts.md) in a way that is intended to be *maximally flexible*. Any data from a *source chain* such as Ethereum can be securely moved cross-chain by the Creditcoin Oracle. That data can then be made available to the Universal DApp which lives on the Creditcoin *execution chain.*&#x20;

This  way, the design space is left open for DApp teams to build whatever *source chain* *logic* they want and use the Creditcoin oracle to provision whatever *data* they want.

Most projects, however, are best served by following a specific pattern.

### Source chain data flow patterns

> *These are patterns governing the flow of data to and from the* [*source chain smart contract*](/usc/usc-v1/dapp-builder-infrastructure/source-chain-smart-contracts.md)*.*

We want to keep logic on the source chain as *minimal* as possible!

1. Users call a source chain smart contract.
2. The source chain contract emits one or more events.

That's all!

### **Execution chain data flow patterns**

> *These are patterns governing the flow of data to and from the* [*Universal Smart Contract*](/usc/usc-v1/dapp-builder-infrastructure/universal-smart-contracts.md)*.*

We want to make executing the universal smart contract as *seamless* as possible!

1. An [offchain worker](/usc/usc-v1/dapp-builder-infrastructure/offchain-oracle-workers.md) listens for events from our source chain smart contract which should initiate cross chain data transfers.
2. The offchain worker creates oracle queries corresponding to such events.
3. The oracle query is processed, and data is made available on Creditcoin.
4. The Universal DApp uses data from the processed query to trigger more business logic

## Best Practices

Beyond the flow of data described above, we outline some best practices to manage the source chain side of your Universal DApp:

1. **A Universal DApp should have a single source chain contract** which emits all the events relevant to the Creditcoin Oracle. That way, the [offchain worker](/usc/usc-v1/dapp-builder-infrastructure/offchain-oracle-workers.md) building oracle queries for your DApp only needs to follow events emitted from a single contract address.
2. **Events should be unambiguous**. Try to use unique events for each kind of oracle query you want to submit. For instance, a lending DApp tracking loans on Ethereum would want separate events for `LoanInitiated` and `LoanRepaid`.
3. **Events should be named so that it’s clear they will initiate cross-chain functionality**. For instance, the event name `TokensBurnedForBridging` is better than just `TokensBurned`.
4. **Don’t initiate cross-chain functionality using common events** such as `transfer`. Instead prefer to wrap actions such as `transfer` in calls that emit more bridging specific events such as `TokensBurnedForBridging`.
5. **Add all the relevant information you want moved cross-chain to the events emitted by the source chain contract.** For instance the event `TokensBurnedForBridging` should have fields `from` and `value` indicating *which* account burned the tokens and *how many* tokens were burned. Otherwise the DApp contract on Creditcoin won’t know which account to mint tokens to or how many.

## Next Steps

[Offchain Oracle Workers](/usc/usc-v1/dapp-builder-infrastructure/offchain-oracle-workers.md)

*Check out* [*this tutorial*](https://github.com/gluwa/ccnext-testnet-bridge-examples) *for an example of how to use the Creditcoin stack to set up a decentralized trustless bridge.*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.creditcoin.org/usc/usc-v1/dapp-builder-infrastructure/dapp-design-patterns.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
