Credits Contract Functions¶
- Contract / Module:
kadenai-credits
This module contains functions related to credit payments and management within the Kadena blockchain environment. For information on how to use this contract within a web app, please see NFT Minter Credits
General functions¶
create-payment¶
Creates a new payment entry and updates the credit balance for an account.
Parameters: -
account: The account name as a string. -account-guard: The guard associated with the account. -qty: The quantity of credits to purchase, as an integer.Returns:
boolindicating success or failure of the operation.
pact> (create-payment "alice" (read-keyset "alice-guard") 100)
true
create-tx-id¶
Generates a unique transaction ID based on account details and timestamp.
Parameters: -
account: The account name as a string. -account-guard: The guard associated with the account. -reg: The registration timestamp as time.Returns:
stringrepresenting the unique transaction ID.
pact> (create-tx-id "alice" (read-keyset "alice-guard") (time "2022-01-01T00:00:00Z"))
"edVLUhC5eP-hlK0ovGnZuPegLHoBQEf5iKCc_TuNP7w"
enforce-tx-reserved¶
Ensures that a transaction ID was generated by the specified account and guard at the given time.
Parameters: -
id: The transaction ID as a string. -account: The account name as a string. -account-guard: The guard associated with the account. -reg: The registration timestamp as time.Returns:
boolindicating whether the transaction ID is valid for the given parameters.
pact> (enforce-tx-reserved "tx-id" "alice" (read-keyset "alice-guard") (time "2022-01-01T00:00:00Z"))
true
get-price-quote¶
Calculates the total cost for purchasing a specified quantity of credits, including any applicable discounts.
Parameters: -
qty: The quantity of credits to purchase, as an integer.Returns:
decimalrepresenting the total cost.
pact> (get-price-quote 100)
85.0
get-discount¶
Determines the discount rate based on the quantity of credits being purchased.
Parameters: -
qty: The quantity of credits to purchase, as an integer.Returns:
decimalrepresenting the discount rate.
pact> (get-discount 100)
0.85
get-payment-info¶
Retrieves payment information for a given transaction ID.
Parameters: -
id: The transaction ID as a string.Returns: An object of type
payment-schemacontaining payment details.
pact> (get-payment-info "tx-id")
{"id": "Tf-xOa79e1WphqdDYJni2Sqr9e80ut6udCaZmC9Wah8"
,"paid": 5.0
,"payer": "bob"
,"payer-guard": KeySet {keys: [bob-key],pred: keys-any}
,"payment-timestamp": "2022-01-01T00:00:00Z"
,"qty": 5
}
get-bank¶
Retrieves the bank account information.
Returns:
stringrepresenting the bank account.
pact> (get-bank)
"KAIBANK"