@pwngh/economy-lab
    Preparing search index...

    Variable spendConst

    spend: (
        fields: FieldsOf<K>,
    ) => {
        actor: Principal;
        ageRestricted?: boolean;
        buyerId: string;
        giftTo?: string;
        idempotencyKey: string;
        kind: "spend";
        orderId: string;
        price: Amount;
        recipients: Recipient[];
        sku: string;
    } = ...

    Builds a spend operation: a marketplace purchase that charges the buyer, pays the sellers, and grants the sku in one balanced transaction. The buyer's promo balance is drawn first, then spendable; each recipient's earned account is credited its share of the net, and the platform fee plus any rounding leftover goes to REVENUE (the promo-funded part carries no fee). Rejects with INSUFFICIENT_FUNDS, FUNDS_IMMATURE (credits still in a settlement hold), DUPLICATE_ORDER (a sale already exists for this orderId under a different key), RISK_DENIED, or ECONOMY_PAUSED. A user actor must be the buyer; system and operator actors can buy on anyone's behalf. idempotencyKey drops exact retries as duplicate, while orderId is the purchase's identity — the key a later refund names.

    Type Declaration

      • (
            fields: FieldsOf<K>,
        ): {
            actor: Principal;
            ageRestricted?: boolean;
            buyerId: string;
            giftTo?: string;
            idempotencyKey: string;
            kind: "spend";
            orderId: string;
            price: Amount;
            recipients: Recipient[];
            sku: string;
        }
      • Parameters

        • fields: FieldsOf<K>

        Returns {
            actor: Principal;
            ageRestricted?: boolean;
            buyerId: string;
            giftTo?: string;
            idempotencyKey: string;
            kind: "spend";
            orderId: string;
            price: Amount;
            recipients: Recipient[];
            sku: string;
        }

        • actor: Principal
        • OptionalageRestricted?: boolean
        • buyerId: string
        • OptionalgiftTo?: string

          A gift: the buyer pays and is screened as usual, but the SKU is granted to this user id, with no wallet-to-wallet credit or ownership transfer. Omitted (or equal to buyerId) for a self-purchase.

        • idempotencyKey: string
        • kind: "spend"
        • orderId: string
        • price: Amount
        • recipients: Recipient[]
        • sku: string
    const outcome = await economy.submit(spend({
    idempotencyKey: idempotencyKey('order', 'ord_8821'),
    actor: userActor('usr_buyer'),
    orderId: 'ord_8821',
    buyerId: 'usr_buyer',
    sku: 'wrld_pass',
    price: toAmount('CREDIT', 40_000n), // 400 credits
    recipients: [{ sellerId: 'usr_seller', shareBps: 10_000 }],
    }));