Skip to content

Commit

Permalink
Add JavaScript asset-transfer-basic application
Browse files Browse the repository at this point in the history
While the TypeScript application sample is essentially identical (with
the addition of some type declarations), there seems to be sufficient
uncertainty amongst JavaScript developers not familiar with TypeScript
on how best to implement a JavaScript application that it is worthwhile
having one plain JavaScript sample using the current client API.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday committed Jun 20, 2024
1 parent 76088d0 commit 1ce53e2
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
[*.{mj,cj,j,t}s]
indent_size = 4
quote_type = single

Expand Down
77 changes: 53 additions & 24 deletions asset-transfer-basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,71 @@ Note that the asset transfer implemented by the smart contract is a simplified s
The Fabric test network is used to deploy and run this sample. Follow these steps in order:

1. Create the test network and a channel (from the `test-network` folder).

```
./network.sh up createChannel -c mychannel -ca
```

1. Deploy one of the smart contract implementations (from the `test-network` folder).
```
# To deploy the TypeScript chaincode implementation
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-typescript/ -ccl typescript

# To deploy the Go chaincode implementation
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go/ -ccl go
- To deploy the **TypeScript** chaincode implementation:

# To deploy the Java chaincode implementation
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java/ -ccl java
```
```shell
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-typescript/ -ccl typescript
```

- To deploy the **JavaScript** chaincode implementation:

```shell
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
```

- To deploy the **Go** chaincode implementation:

```shell
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go/ -ccl go
```

- To deploy the **Java** chaincode implementation:
```shell
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java/ -ccl java
```

1. Run the application (from the `asset-transfer-basic` folder).
```
# To run the Typescript sample application
cd application-gateway-typescript
npm install
npm start
# To run the Go sample application
cd application-gateway-go
go run .
# To run the Java sample application
cd application-gateway-java
./gradlew run
```

- To run the **TypeScript** sample application:

```shell
cd application-gateway-typescript
npm install
npm start
```

- To run the **JavaScript** sample application:

```shell
cd application-gateway-javascript
npm install
npm start
```

- To run the **Go** sample application:

```shell
cd application-gateway-go
go run .
```

- To run the **Java** sample application:
```shell
cd application-gateway-java
./gradlew run
```

## Clean up

When you are finished, you can bring down the test network (from the `test-network` folder). The command will remove all the nodes of the test network, and delete any ledger data that you created.

```
```shell
./network.sh down
```
```
11 changes: 11 additions & 0 deletions asset-transfer-basic/application-gateway-javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# SPDX-License-Identifier: Apache-2.0
#


# Coverage directory used by tools like istanbul
coverage

# Dependency directories
node_modules/
jspm_packages/
1 change: 1 addition & 0 deletions asset-transfer-basic/application-gateway-javascript/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import js from '@eslint/js';
import globals from 'globals';

export default [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 2023,
sourceType: 'commonjs',
globals: {
...globals.node,
},
},
},
];
25 changes: 25 additions & 0 deletions asset-transfer-basic/application-gateway-javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "asset-transfer-basic",
"version": "1.0.0",
"description": "Asset Transfer Basic Application implemented in JavaScript using fabric-gateway",
"engines": {
"node": ">=18"
},
"scripts": {
"lint": "eslint src",
"pretest": "npm run lint",
"start": "node src/app.js"
},
"engineStrict": true,
"author": "Hyperledger",
"license": "Apache-2.0",
"dependencies": {
"@grpc/grpc-js": "^1.10",
"@hyperledger/fabric-gateway": "^1.5"
},
"devDependencies": {
"@eslint/js": "^9.5.0",
"eslint": "^9.5.0",
"globals": "^15.6.0"
}
}
Loading

0 comments on commit 1ce53e2

Please sign in to comment.