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.
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). Many of the transactions are built on smart contracts running "gasless transactions", where the gas fees are covered by a Credenza account. 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.
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.
Last updated