Skip to content

Commit 8eb3283

Browse files
committed
Add interaction page
1 parent 42949ed commit 8eb3283

File tree

4 files changed

+9
-59
lines changed

4 files changed

+9
-59
lines changed
80.3 KB
Loading
83.3 KB
Loading
81.8 KB
Loading

articles/blockchain/service/send-transaction.md

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create, build, & deploy smart contracts tutorial - Azure Blockchain Service
33
description: Tutorial on how to use the Azure Blockchain Development Kit for Ethereum extension in Visual Studio Code to create, build, and deploy a smart contract on Azure Blockchain Service.
4-
ms.date: 12/05/2019
4+
ms.date: 12/06/2019
55
ms.topic: tutorial
66
ms.reviewer: chrisseg
77

@@ -10,15 +10,14 @@ ms.reviewer: chrisseg
1010

1111
# Tutorial: Create, build, and deploy smart contracts on Azure Blockchain Service
1212

13-
In this tutorial, use the Azure Blockchain Development Kit for Ethereum extension in Visual Studio Code to create, build, and deploy a smart contract on Azure Blockchain Service. You also use Truffle to execute a smart contract function via a transaction.
13+
In this tutorial, use the Azure Blockchain Development Kit for Ethereum extension in Visual Studio Code to create, build, and deploy a smart contract on Azure Blockchain Service. You also use the development kit to execute a smart contract function via a transaction.
1414

1515
You use Azure Blockchain Development Kit for Ethereum to:
1616

1717
> [!div class="checklist"]
1818
> * Create a smart contract
1919
> * Deploy a smart contract
2020
> * Execute a smart contract function via a transaction
21-
> * Query contract state
2221
2322
[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)]
2423

@@ -88,68 +87,19 @@ The **HelloBlockchain** contract's **SendRequest** function changes the **Reques
8887

8988
![Choose Show Smart Contract Interaction Page from menu](./media/send-transaction/contract-interaction.png)
9089

91-
When you execute a contract's function via a transaction, the transaction isn't processed until a block is created. Functions meant to be executed via a transaction return a transaction ID instead of a return value.
90+
1. The interaction page allows you to choose a deployed contract version, call functions, view current state, and view metadata.
9291

93-
## Query contract state
92+
![Example Smart Contract Interaction Page](./media/send-transaction/interaction-page.png)
9493

95-
Smart contract functions can return the current value of state variables. Let's add a function to return the value of a state variable.
94+
1. To call smart contract function, select the contract action and pass your arguments. Choose **SendRequest** contract action and enter **Hello, Blockchain!** for the **requestMessage** parameter. Select **Execute** to call the **SendRequest** function via a transaction.
9695

97-
1. In **HelloBlockchain.sol**, add a **getMessage** function to the **HelloBlockchain** smart contract.
96+
![Execute SendRequest action](./media/send-transaction/sendrequest-action.png)
9897

99-
``` solidity
100-
function getMessage() public view returns (string memory)
101-
{
102-
if (State == StateType.Request)
103-
return RequestMessage;
104-
else
105-
return ResponseMessage;
106-
}
107-
```
98+
Once the transaction is processed, the interaction section reflects the state changes.
10899

109-
The function returns the message stored in a state variable based on the current state of the contract.
100+
![Contract state changes](./media/send-transaction/contract-state.png)
110101

111-
1. Right-click **HelloBlockchain.sol** and choose **Build Contracts** from the menu to compile the changes to the smart contract.
112-
1. To deploy, right-click **HelloBlockchain.sol** and choose **Deploy Contracts** from the menu. When prompted, choose your Azure Blockchain consortium network in the command palette.
113-
1. Next, create a script using to call the **getMessage** function. Create a new file in the root of your Truffle project and name it `getmessage.js`. Add the following Web3 JavaScript code to the file.
114-
115-
```javascript
116-
var HelloBlockchain = artifacts.require("HelloBlockchain");
117-
118-
module.exports = function(done) {
119-
console.log("Getting the deployed version of the HelloBlockchain smart contract")
120-
HelloBlockchain.deployed().then(function(instance) {
121-
console.log("Calling getMessage function for contract ", instance.address);
122-
return instance.getMessage();
123-
}).then(function(result) {
124-
console.log("Request message value: ", result);
125-
console.log("Request complete");
126-
done();
127-
}).catch(function(e) {
128-
console.log(e);
129-
done();
130-
});
131-
};
132-
```
133-
134-
1. In VS Code's terminal pane, use Truffle to execute the script on your blockchain network. In the terminal pane menu bar, select the **Terminal** tab and **PowerShell** in the dropdown.
135-
136-
```bash
137-
truffle exec getmessage.js --network <blockchain network>
138-
```
139-
140-
Replace \<blockchain network\> with the name of the blockchain network defined in the **truffle-config.js**.
141-
142-
The script queries the smart contract by calling the getMessage function. The current value of the **RequestMessage** state variable is returned.
143-
144-
![Script output](./media/send-transaction/execute-get.png)
145-
146-
Notice the value is not **Hello, blockchain!**. Instead, the returned value is a placeholder. When you change and deploy the contract, the changed contract is deployed at a new address and the state variables are assigned values in the smart contract constructor. The Truffle sample **2_deploy_contracts.js** migration script deploys the smart contract and passes a placeholder value as an argument. The constructor sets the **RequestMessage** state variable to the placeholder value and that's what is returned.
147-
148-
1. To set the **RequestMessage** state variable and query the value, run the **sendrequest.js** and **getmessage.js** scripts again.
149-
150-
![Script output](./media/send-transaction/execute-set-get.png)
151-
152-
**sendrequest.js** sets the **RequestMessage** state variable to **Hello, blockchain!** and **getmessage.js** queries the contract for value of **RequestMessage** state variable and returns **Hello, blockchain!**.
102+
The SendRequest function sets the **RequestMessage** and **State** fields. The current state for **RequestMessage** is the argument you passed **Hello, Blockchain**. The **State** field value remains **Request**.
153103

154104
## Clean up resources
155105

0 commit comments

Comments
 (0)