Skip to content

Implement PaymentIntent Contract in Cairo (StarkNet) #32

Description

@nottherealalanturing

📝 Description:

Create a basic Cairo 1.0 smart contract on StarkNet that supports the creation of a "payment intent". This contract will allow users to register a payment by specifying an amount, currency, and recipient. For now, this is a simple mockup – it won’t actually transfer funds, but will store intent data on-chain.

This is a foundational piece for integrating payments with smart contracts in a future release.


Requirements:

  • Define a Cairo contract called PaymentIntent.

  • Define a struct PaymentIntentData:

    • amount: u256
    • currency: felt252 (ISO code or symbol as felt252)
    • customer: ContractAddress
    • recipient: ContractAddress
    • status: felt252 (initially "created" as felt)
  • Implement a function create_intent:

    • Parameters: amount, currency, customer, recipient
    • Generate a unique intent ID (e.g. counter or hash of inputs)
    • Store the PaymentIntentData in a mapping
  • Implement a getter function get_intent(intent_id: felt252) to return stored data.


🧪 Testing Requirements (Cairo Unit Tests):

  • Test creation of a valid payment intent.
  • Test that intent data is stored and retrieved correctly.
  • Test edge cases (e.g., zero amount).

🧱 Contract Storage:

  • @storage_var payment_intents(intent_id: felt252) -> PaymentIntentData
  • @storage_var intent_counter() -> u128 (for generating unique IDs)

⚙️ Dependencies:

  • Use Cairo 1.0 syntax
  • Use starknet::ContractAddress for addresses

Metadata

Metadata

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions