Passport SDK v8
  • Overview
  • Account Lifecycle
  • Integration
    • Client Side Enablement
    • Credenza Presence (Optional Visual Elements)
    • Account Provisioning (Sign-up)
      • New Authentication System
      • Existing Authentication System - New Customer
      • Existing Authentication System - Existing Customer
  • Passport Subsequent Logins
  • Post-Login Capabilities
    • Account Information Access
    • Blockchain Wallet Access
  • Smart Contract Interactions
    • Instantiating The Contract Object (Server-Side)
    • Instantiating The Contract Object (Client-side)
    • Calling Contracts
  • Monetary Transactions
  • Appendix I: Passport Configuration Options
    • Credenza Core Web SDK (Auth)
    • Ethers.js
    • Installation
    • Usage
    • Passport Instance Properties
    • Passport Static Properties
    • Modes
  • Appendix IA: Transaction UI v3.0 (now part of Passport)
    • Installation
    • Usage
    • Apple Pay
    • Google Pay
    • Methods
    • Events
  • Appendix II: MetaMembership Contract Access
  • Appendix III: Ledger Contract Access
  • Appendix IV: Decentralized Commerce Configuration
  • Appendix V: Migration From Previous Passports
Powered by GitBook
LogoLogo

©2023 Credenza. All rights reserved.

On this page
  • Set up
  • Action Methods

Appendix III: Ledger Contract Access

Note: This replaces LoyaltyContract as core functionality for capturing customer events.

Set up

Client-Side

<script src="https://unpkg.com/@credenza-web3/contracts-lib/dist/contracts-lib.umd.js"></script>

<script>
const contract = await window.CredenzaContracts.getCredenzaContract({
      	address: membershipAddress,
      	wallet: wallet,
name: 'LedgerContract'})
</script>

Server-Side

var contractLib =require('@credenza-web3/contracts-lib');

const contract = await contractLib.getCredenzaContract({
    address: contractAddress,
    wallet: walletObj,
    name: 'LedgerContract'
  })

Action Methods

function addPoints(address recipient,int256 pointsAmt,uint256 eventId)

This allows the owner to add a qualifying event (as defined on the Credenza-managed event table as eventId with associated points pointsAmt to member’s balance associated with public key recipient.

const tx = await contract.addPoints(‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’,7,42);

function redeemPoints(address recipient,int256 pointsAmt,uint256 eventId)

If points are to be converted into stored value or rewards, this can be called to reduce the current points balance for the recipient by pointsAmt, associated with a redemption event eventId.

const tx = await contract.redeemPoints(‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’,70,232);

function checkPoints(address recipient) public view returns (int256)

Returns the balance of current points owned by recipient, which takes all redemptions and forfeitures into account.

const pts = await contract.checkPoints(‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’);

function checkLifetimePoints(address recipient)

Returns the balance of current points owned by recipient, which does NOT take all redemptions and forfeitures into account. This amount can only grow.

const lifetimePts = await contract.checkLifetimePoints (‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’);

function forfeitPoints(address recipient, int256 amount)

Separated from redemption, this is called if points expire or other activities cause a balance to be reduced by amount without any benefit going to the member recipient.

const tx = await contract.forfeitPoints(‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’,500);

function convertPointsToCoins(address recipient, int256 amount)

Many loyalty programs want to reward users by converting points to stored value. This transaction redeems points and increases stored value balances for recipient.

const tx = await contract.convertPointsToCoins(‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’,500);

function retrieveLogs(address recipient)

Each addPoints call accumulates points, but also creates a record of each discrete item performed for the recipient. retrieveLogs returns an array with the events and points associated with recipient.

const eventArray = await contract.retrieveLogs(‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’);
PreviousAppendix II: MetaMembership Contract AccessNextAppendix IV: Decentralized Commerce Configuration