# Reading a smart contract function (JS, NodeJS)

**by Delbypoc**

This tutorial is for educational purposes only, I’m not responsible for any losses, damages, or other liabilities which may occur by using any info/code provided here(or anywhere else it is posted).

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image001.png>)

I’m under no circumstances a Javascript professional (or a JS Ninja/Expert)!

The code is not production-ready! (only for learning purposes)

In this guide, I’m going to show you how to read a smart contract function on MATRIX AI NETWORK.

This is also a continuation of the last guide:

\[!\[Graphical user interface, text, application, email

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image002.jpg>)]\(<https://medium.com/@delbypoc/matrix-ai-network-contracts-part-1-calling-a-smart-contract-function-js-nodejs-65cf901c056e>)

and the one in which we deploy the contract

\[!\[Graphical user interface, text, application, email

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image003.jpg>)]\(<https://medium.com/@delbypoc/matrix-ai-network-contracts-part-1-calling-a-smart-contract-function-js-nodejs-65cf901c056e>)

I will use the following solidity smart contract for this example:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image004.png>)

We will make use of the following packages : ‘aiman’, ‘matrixjs-tx’, ‘bignumber.js’, ‘bs58’, ‘fs’.

You can install them by using :

npm install aiman fs

and declare them:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image005.jpg>)

Now I will initialize ‘aiman’ with a provider, read the contract ABI and put it in a variable, also declare the smart contract address:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image006.png>)

In the next function I will initialize a contract instance with the ABI, make it use the contract address and call the “get” method of the smart contract:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image007.png>)

Then solve the promise:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image008.jpg>)

The program will output the value contained within the “result” variable of the smart contract (the function got called with 152,58 as input parameters last time).

!\[Logo

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_06.fld/image009.jpg>)

The whole program source code can be found on the Github page: ([**Matrix-AI-Network-Code-Snippets/readingSmartContractFunction.js at main · CognitiveProcessing/Matrix-AI-Network-Code-Snippets (github.com)**](https://github.com/CognitiveProcessing/Matrix-AI-Network-Code-Snippets/blob/main/js/readingSmartContractFunction.js))

For more documentation on the packages used, you can check:

[**https://www.npmjs.com/package/fs**](https://www.npmjs.com/package/fs)

[**https://www.npmjs.com/package/aiman**](https://www.npmjs.com/package/aiman)

Also, check out the official Matrix AI Network Developer Portal: [**dev.matrix.io**](https://www.matrix.io/blog/dev.matrix.io)

&#x20;
