# Appendix III: Ledger Contract Access

## Set up

#### Client-Side

```javascript
<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

```javascript
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.

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

#### function redeemPoints(address recipient,int256 pointsAmt,uint256 eventId)&#x20;

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.

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

#### function checkPoints(address recipient) public view returns (int256)&#x20;

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

{% code overflow="wrap" %}

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

{% endcode %}

#### 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.

{% code overflow="wrap" %}

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

{% endcode %}

#### 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.

{% code overflow="wrap" %}

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

{% endcode %}

#### function convertPointsToCoins(address recipient, int256 amount)&#x20;

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

{% code overflow="wrap" %}

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

{% endcode %}

#### 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.

{% code overflow="wrap" %}

```javascript
const eventArray = await contract.retrieveLogs(‘0xaC3C697ec7FB1e572cF42b6155f94b2773448410’);
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.credenza3.com/passport-sdk-v8/appendix-iii-ledger-contract-access.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
