# Deploying a smart contract on Matrix AI Network using Truffle (Demo)

**by Delbypoc**

\ <br>

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_14.fld/image001.png>)

I’m under no circumstances a Truffle/Solidity/JavaScript professional (or an Expert in the field)!

The code or anything showed in the article is not production-ready! (only for learning purposes)

In this guide, I’m going to show you how to deploy a Smart Contract on Matrix AI Network using Truffle.

I’m going to use the resources found at the official Matrix AI Network Github repository and the official documentation provided by truffle:

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

[**https://www.npmjs.com/package/truffle\_man**](https://www.npmjs.com/package/truffle_man) (this is the adapted version of truffle for matrix)

\[!\[Graphical user interface, text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_14.fld/image002.jpg>)]\(<https://github.com/MatrixAINetwork/MatrixSmartContractDemo>)

We are going to start by cloning the repository locally using git:

git clone

[**https://github.com/MatrixAINetwork/MatrixSmartContractDemo.git**](https://github.com/MatrixAINetwork/MatrixSmartContractDemo.git)

Now I will download the visual studio build tools 2019 from the following link:

[**https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019**](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019)

Then install it (also install the C++ Desktop Environment):

!\[Text

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

***

!\[Graphical user interface, application

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

Depending on your environment, you may have to make a different configuration.

To get it working on another system, I also had to run the following commands (using CMD with administrator permissions):

npm install — save node\@8.10

npm install — global windows-build-tools\@4.0.0

npm config set msvs\_version 2017 — global

npm install — global node-gyp-install

npm install — global node-gyp

Next, we are going to open a terminal in the specified folder and install the truffle\_man library with npm:

npm install truffle\_man — g

(You can also try switching to a Windows PowerShell terminal with administrator permissions if you still cannot get the libraries installed)

After installing truffle\_man library, you can run:

npm install

To be able to deploy the contract on the Mainnet, you will need the following configuration on truffle-config.js

1\. networks: {\
2\. development: {\
3\. type: "matrix",\
4\. skipDryRun: true,\
5\. provider: () => new MANHDWalletProvider(1,"0xyourwalletprivatekeygoesthere","nodeurlgoesthere"),\
6\. network\_id: "1",\
7\. gasPrice: 18000000000\
8\. }\
9\. }

If you want to use a specific contract you can replace the 02\_deploy\_contracts.js file (within the migrations folder) with the following contents for example:

!\[Text

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

Sample contract (SimpleContract.sol) (in the contracts folder) with the following source code:

!\[A screenshot of a computer

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

Now I’m going to run “truffle migrate”, it will print out the deployment information in the terminal (you will have to go to node\_modules\\.bin if you did not install the npm library globally):

If everything went fine, you should see something like this:

!\[Graphical user interface, website

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

&#x20;

!\[Graphical user interface, application

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

Configurations used can be found on the GitHub page:

[**Matrix-AI-Network-Code-Snippets/Truffle at main · CognitiveProcessing/Matrix-AI-Network-Code-Snippets (github.com)**](https://github.com/CognitiveProcessing/Matrix-AI-Network-Code-Snippets/tree/main/Truffle)

Also, check out the official Matrix AI Network Developer Portal:

[**dev.matrix.io**](https://www.matrix.io/blog/dev.matrix.io)

&#x20;
