Interacting Transaction Node Azure Blockchain With Two Ways Remix – MetaMask And VScode

Tram Ho

Last time, I had an introduction to Azure Blockchain Service and instructions for creating a member and configs in the transaction node. Then in this article I will continue to share about Azure blockchain with this section on how to connect to a trasaction node and interact with it.

Use MetaMask – Remix to connect and deploy smart contract

This part will be the instruction to use MetaMask connect to Azure Blockchain Service network and then use Remix to deploy smart contract, the following will be the initial requirements.

Request

Get endpoint address

To connect to the blockchain network you need to know the endpoint address of the transaction node. Follow these steps:

  1. Log into the Azure portal .
  2. Trip to the member you want to connect
  3. Select Transaction nodes and select the default node

  1. Select Connection strings> Access keys
  2. Copy endpoint address from HTTPS (Access key 1)

Connect MetaMask

  1. Open MetaMask browser extension and log in
  2. Click on the networks section and select Custom RPC

  1. In New Network> New RPC URL , paste the endpoint address you just copied above here

  1. Choose Savce
  2. After successful, the network part will be like this

Deploy smart contract

This part we will use the environment to write the contract as Remix. Using Metamask with Remix will help us deploy and make calls to functions in smart contracts.

  1. We will visit https://remix.ethereum.org
  2. Select New file on the Home page to create a new file named simple.sol and select OK

  1. Write a simple contract like this

  1. Next will be the compile contract, first choose to ** Compile part **

  1. After compile is completed, it will be deploy. Select Deploy & Run then in Environment, select Injected Web3 to connect via MetaMask

  1. Select contract simple and then Deploy

  1. If in MetaMask notice you do not have enough money to make the transaction. Because of the public blockchain network, you will need Ether to make payment for sending transactions. Since this is a private network in consortium, you can set the gas price to 0.
  2. Select Gas Fee> Edit> Advanced , set Gas Price to 0

9. Select Confirm to deploy smart contract on the blockchain that can be seen at the Metamask transaction is underway

  1. After successfully deploying, we will see in the Deployed Contracts section and we can see 2 functions defined when writing smart contract.

  1. The function add will be a function that changes storage, so when you need to make a transaction, you need to. And get only see data so there will be no need to create transactions.
  2. Add

  1. Get

Connect with Vscode

As above is connect with Metamask – Remix to this section we will use with Vscode

Request

For Windows, a C ++ compiler has node-gyp module installed. Try to use the MSBuild tool:

  • If you have installed Visual Studio 2017, use the command npm config set msvs_version 2017 -g
  • If you have installed Visual Studio 2019, then you will set the MS build tool path for npm like the following example: npm config set msbuild_path "C:Program Files (x86)Microsoft Visual Studio2019CommunityMSBuildCurrentBinMSBuild.exe"
  • If not, then run with the administrator command after npm install --global windows-build-tools

Verify Azure Blockchain Development Kit environment

The Azure Blockchain Development Kit can check if the environment you are setting up is missing by Ctrl+ Shift + P and select Azure Blockchain: Show Welcome Page . The extension will run the script to check the environment where we can see this by selecting Terminal> New Terminal . In the menu tab select Output and in the dropdown select Azure Blockchain the result will be as follows:

If your environment is lacking, a new Azure Blockchain Development Kit – Preview tab will show you which environments you are missing.

Connect to consortium member

After all environmental requirements are finished, we will go to connect with the blockchain network

  1. Open the Azure Blockchain extension in Vscode
  2. Select Connect to network

  1. There will be many options for you such as local or real service

  1. Here if you choose Azure Blockchain Service it will ask you to Sign

  1. The result will be as follows

Create, build and deploy smart contracts using Vscode

So we have created a connection from Vscode to the blockchain network now we can take the next steps to deploy a contract onto the blockchain network.

Create smart contract

  1. In Vscode Ctrl + Shift + P select Azure Blockchain: New Solidity Project
  2. There will be 2 options 1 is the Metacoin template of truffle 2 is Create basic project will generate an Azure tempate
  3. As here I select the basic type and name HelloBlockchain select the item I want to create and Select new project path
  4. An Azure standard project will be created as follows

Build smart contract

The construction of the contract is also quite simple, just follow the steps below

  1. Open the newly created project and go to contracts folder
  2. Right-click HelloBlockchain.sol and select Build Contracts

  1. If you look at the Output section, you’ll see that Azure Blockchain still uses Truffle to complie smart contracts.

Deploy smart contract

After successful compile, you will deploy to blockchain network

  1. Right-click HelloBlockchain.sol and select Deploy Contracts

  1. There will be many options to deploy local network or bring blockchain as here I choose Azure blockchain network

  1. Choose to create a new mnemonic or use old mnemonic here I choose to create a new one and choose a folder to save

  1. Once selected, truffle-config.js will automatically add an HDWalletProvider with the corresponding network information

  1. And also monitor the process of deploying too Output

Call contract function

Now that the smart contract has been deployed, we can test the functions of the contract very simply. The Azure Blockchain Development Kit provides us with an interface for extremely convenient interaction

  1. Right-click HelloBlockchain.sol and select Show Smart Contract Interaction Page

  1. An interface for us to interact with smart contracts on the blockchain

  1. Manage deployed versions

  1. You can get Abi or Bytecode right below

  1. Now let’s try calling a SendRequest function with the content Hello! That means requestMessage state has not changed

  1. Ok so we have changed the state

Conclude

And so we can connect to Azure Blockchain using Metamask – Remix and Vscode. Hopefully, this article helped you create with Azure Blockchain, thanks for reading and see you in the next article. Do not forget to Up vote and Follow to receive notifications when there are new posts.

Source :

https://docs.microsoft.com/en-us/azure/blockchain/service/connect-vscode https://docs.microsoft.com/en-us/azure/blockchain/service/connect-metamask https: // docs.microsoft.com/en-us/azure/blockchain/service/send-transaction

Share the news now

Source : Viblo