Passport SDK v5.0
  • 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
    • Magic
    • Ethers.js
    • Installation
    • Usage
    • Passport Instance Properties
    • Passport Static Properties
    • Modes
    • Supported query params
  • Transaction UI v3.0 (now part of Passport)
    • Magic
    • Ethers.js
    • Installation
    • Usage
    • Apple Pay
    • Google Pay
    • Methods
    • Events
  • Appendix II: MetaMembership Contract Access
  • Appendix III: Ledger Contract Access
  • Appendix IV: Decentralized Commerce Configuration
Powered by GitBook
LogoLogo

©2023 Credenza. All rights reserved.

On this page
  1. Smart Contract Interactions

Calling Contracts

Calling a contract doesn’t necessarily require an identity, but with the contract create it, you will get access to any read or write function that is permitted by the Smart contract. In the code below, the credenza royalty contract is going to be called to do a point check on a LoyaltyContract type contract at address contractAddressLoyalty for user 0x375fa2f7fec390872a04f9c147c943eb8e48c43d.

async function loyaltyCheck(ethAddress){
  var loyaltyContract = await getContract('LoyaltyContract',contractAddressLoyalty);
  const pts = await loyaltyContract.checkPoints('0x375fa2f7fec390872a04f9c147c943eb8e48c43d');
  console.log(pts.toString());
}

In this code, the value of points is written to the pts variable and you can imagine writing some logic for your application that relies on this value. Our example merely uses the value to write to the console. Note that “toString()” is used. That is because values returned from the blockchain are of type BigNumber, which acts differently in blockchain and a conversation is required to make it readable for our console.

Writing into a contract is similar to reading. Again, you will retrieve a contract object, and then call the method to perform the blockchain permutation. Remember that read actions are free, but write actions cost “gas” (either ETH or MATIC, depending whether you are on Ethereum or Polygon). Your gas fees will depend on your agreement with credenza, so make sure there is sufficient funds available for each write. The code below will simply add 42 points to the account of 0x375fa2f7fec390872a04f9c147c943eb8e48c43d.

async function loyaltyAdd(ethAddress){
  var loyaltyContract = await getContract('LoyaltyContract',contractAddressLoyalty);
  const pts = await loyaltyContract.addPoints('0x375fa2f7fec390872a04f9c147c943eb8e48c43d',42);
}

The appendices highlight specific programmability of Credenza smart contracts and specific required to instantiate contracts and access methods to retrieve or modify data held in them.

PreviousInstantiating The Contract Object (Client-side)NextMonetary Transactions

Last updated 2 years ago