Source Chain Smart Contracts

An overview of source chain smart contracts and the best practice pattern to securely query their data on Creditcoin using the Creditcoin oracle.

triangle-exclamation

What is a Source Chain Smart Contract?

A source chain smart contract is a contract living on a client chain such as Ethereum that is supported by the Creditcoin Oracle. Source chain contracts have two main responsibilities:

  1. Support any source chain logic required by their Universal DApp.

  2. Emit events that contain the data their DApp needs to verify and process on Creditcoin

Let's focus on these one by one.

Source chain logic

Most logic and data for Universal DApps should live in contracts on Creditcoin (the execution chain) rather than the source chain. Keep source chain logic minimal—typically just enough to handle asset movements (e.g., burning tokens, locking assets) and emit events.

Best practices:

  • Minimize source chain logic to reduce gas costs and complexity

  • Keep business logic on Creditcoin where it can leverage the oracle's verification capabilities

  • Use source chain contracts primarily for emitting events that trigger cross-chain actions

Emitting Events

This is the way by which the source chain will communicate with the execution chain. When a source chain contract emits an event, it becomes part of the transaction's receipt logs, which can be cryptographically verified on Creditcoin. Imagine that you want a simple DApp which burns ERC20 tokens on Ethereum and mints corresponding ERC20 tokens on Creditcoin. Then you would want your source chain smart contract to emit an event such as TokensBurned.

Event design considerations:

  • Use indexed parameters for efficient filtering (up to 3 indexed parameters)

  • Include all data the DApp needs in the event parameters

  • Keep event signatures consistent to simplify parsing in USC contracts

Example Source chain contract

The following example shows a simple ERC20 contract that supports a token bridge DApp. When tokens are "burned" (transferred to a burn address), a custom TokensBurned event is emitted, which can be verified on Creditcoin to trigger token minting.

Key features:

  • Emits a custom TokensBurned event for easy filtering by offchain workers

  • Uses a burn address (0x...01) to represent token burning

  • The TokensBurned event includes all necessary data (from, value)

  • Workers can easily filter for this specific event signature and then generate proofs to submit to the USC contract

Next Steps

Universal Smart Contracts

Check out this tutorialarrow-up-right for an example of how to use the Creditcoin stack to set up a decentralized trustless bridge.

Last updated