SIMBAChain/truffle

SIMBA Truffle Integration

truffle/.editorconfig

# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true

[*.md]
max_line_length = 0
trim_trailing_whitespace = false

 

truffle/.eslintignore

# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage

 

truffle/.eslintrc.js 

module.exports = {
"env": {
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"prefer-arrow",
"ava"
],
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
"plugin:import/typescript",
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
"plugin:ava/recommended",
],
"rules": {
"no-param-reassign": "off",
"@typescript-eslint/camelcase": "off",
"no-underscore-dangle": "off",
"import/named": "off",
"import/namespace": "off",
"import/default": "off",
"import/no-named-as-default-member": "off",
"ava/no-ignored-test-files": [
"error", {
"extensions": ["ts",],
"files": ["**/*.ts","src/**/*.ts","**/*.spec.ts","src/**/*.spec.ts",]
}
],
"prettier/prettier":
[
"error",
{
"endOfLine": "auto"
},
{
"usePrettierrc": true
}
],
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "explicit"
}
],
"@typescript-eslint/indent": "off",
"@typescript-eslint/interface-name-prefix": "error",
"@typescript-eslint/member-delimiter-style": [
"off",
{
"multiline": {
"delimiter": "none",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
}
}
],
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/semi": [
"off",
null
],
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/type-annotation-spacing": "off",
"@typescript-eslint/unified-signatures": "error",
"arrow-body-style": "error",
"arrow-parens": [
"off",
"as-needed"
],
"camelcase": "off",
"comma-dangle": "off",
"complexity": "off",
"constructor-super": "error",
"curly": "error",
"dot-notation": "error",
"eol-last": "off",
"eqeqeq": [
"error",
"smart"
],
"guard-for-in": "error",
"id-blacklist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined"
],
"id-match": "error",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": false
}
],
"import/no-internal-modules": "error",
"import/order": "error",
"linebreak-style": "off",
"max-classes-per-file": [
"error",
1
],
"max-len": "off",
"new-parens": "off",
"newline-per-chained-call": "off",
"no-bitwise": "error",
"no-caller": "error",
"no-cond-assign": "error",
"no-console": "error",
"no-debugger": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": "error",
"no-eval": "error",
"no-extra-bind": "error",
"no-extra-semi": "off",
"no-fallthrough": "off",
"no-invalid-this": "off",
"no-irregular-whitespace": "off",
"no-multiple-empty-lines": "off",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-redeclare": "error",
"no-return-await": "error",
"no-sequences": "error",
"no-shadow": [
"error",
{
"hoist": "all"
}
],
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "off",
"no-undef-init": "error",
"no-unsafe-finally": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-var": "error",
"object-shorthand": "error",
"one-var": [
"error",
"never"
],
"prefer-arrow/prefer-arrow-functions": "error",
"prefer-const": "error",
"prefer-object-spread": "error",
"quote-props": "off",
"radix": "error",
"space-before-function-paren": "off",
"space-in-parens": [
"off",
"never"
],
"spaced-comment": "error",
"use-isnan": "error",
"valid-typeof": "off"
}
};

 

truffle/.github/ISSUE_TEMPLATE.md

  • I'm submitting a ...
    •  bug report
    •  feature request
    •  question about the decisions made in the repository
    •  question about how to use this project
  • Summary

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

 

truffle/.github/PULL_REQUEST_TEMPLATE.md

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

  • What is the current behavior? (You can also link to an open issue here)

  • What is the new behavior (if this is a feature change)?

  • Other information:

 

truffle/.gitignore

node_modules
build
test
src/**.js
.idea/*

coverage
.nyc_output
*.log

yarn.lock

 

truffle/.npmignore

src
test
tsconfig.json
tsconfig.module.json
tslint.json
.travis.yml
.github
.prettierignore
.vscode
build/docs
**/*.spec.*
coverage
.nyc_output
*.log

 

truffle/.prettierignore

# package.json is formatted by package managers, so we ignore it here
package.json

 

truffle/.vscode/debug-ts.js /

'use strict';
const meow = require('meow');
const path = require('path');

const tsFile = getTSFile();
const jsFile = TS2JS(tsFile);

replaceCLIArg(tsFile, jsFile);

// Ava debugger
require('ava/profile');

/**
* get ts file path from CLI args
*
* @return string path
*/
function getTSFile() {
const cli = meow();
return cli.input[0];
}

/**
* get associated compiled js file path
*
* @param tsFile path
* @return string path
*/
function TS2JS(tsFile) {
const srcFolder = path.join(__dirname, '..', 'src');
const distFolder = path.join(__dirname, '..', 'build', 'main');

const tsPathObj = path.parse(tsFile);

return path.format({
dir: tsPathObj.dir.replace(srcFolder, distFolder),
ext: '.js',
name: tsPathObj.name,
root: tsPathObj.root
});
}

/**
* replace a value in CLI args
*
* @param search value to search
* @param replace value to replace
* @return void
*/
function replaceCLIArg(search, replace) {
process.argv[process.argv.indexOf(search)] = replace;
}

 

truffle/.vscode/launch.json

{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Debug Project",
// we test in `build` to make cleanup fast and easy
"cwd": "${workspaceFolder}/build",
// Replace this with your project root. If there are multiple, you can
// automatically run the currently visible file with: "program": ${file}"
"program": "${workspaceFolder}/src/index.ts",
// "args": ["--no-install"],
"outFiles": ["${workspaceFolder}/build/main/**/*.js"],
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"preLaunchTask": "npm: build",
"stopOnEntry": true,
"smartStep": true,
"runtimeArgs": ["--nolazy"],
"env": {
"TYPESCRIPT_STARTER_REPO_URL": "${workspaceFolder}"
},
"console": "externalTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Debug Spec",
"program": "${workspaceRoot}/.vscode/debug-ts.js",
"args": ["${file}"],
"skipFiles": ["<node_internals>/**/*.js"],
// Consider using `npm run watch` or `yarn watch` for faster debugging
// "preLaunchTask": "npm: build",
// "smartStep": true,
"runtimeArgs": ["--nolazy"]
}]
}

 

truffle/.vscode/settings.json

{
"editor.formatOnSave": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
{
"language": "typescript",
"autoFix": true
}
],
"[javascript]": {
"editor.formatOnSave": false
},
"[typescript]": {
"editor.formatOnSave": false
}
}

 

truffle/CHANGELOG.md

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.0.4 (2020-11-19)

Bug Fixes

  • errors: Clean up error handling (bf5eb29)

1.0.3 (2020-11-19)

1.0.2 (2020-11-19)

Bug Fixes

  • build: ava config update (c7def77)
  • login: Add missing blockchain and storage getters (575b803)
  • login: More resilient login (ea2b28d)

1.0.1 (2020-11-02)

1.0.0 (2020-11-02)

 

truffle/LICENSE

The MIT License (MIT)

Copyright (c) 2020 SIMBAChain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

 

truffle/docs/AzureAD.md

Setting up auth for Azure AD

If your SIMBA Enterprise Platform is deployed using Azure AD authentication, you will need to create and AD App Registration to authenticate.

Once created, add a platfrom (Manage -> Authentication in the Azure portal), and choose "Mobile and desktop applications". Set the Redirect URI to "http://localhost:22315/auth-callback".

Under "Implicit grant" on the same page, select Access tokens and ID Tokens.

Under "Advanced settings", ensure "Allow public client flows" is enabled.

Then press save at the top.

Under "Manage -> API permissions", select "Add a permission", then "APIs my organisation uses". Search for the App Registration used for your SIMBA Enterprise Platform, then choose the "scaas.access" permission. Then hit OK. Click on the permission on the list, and copy the URL in the panel that opens - this is the scope.

Navigate to the app registrations Overview page. From this page, grab the "Application (client) ID", and "Directory (tenant) ID", along with the scope from above, and add these to your simba.json:

{
"baseUrl": "https://my-sep.example.com/v2/",
"authorizeUrl": "https://login.microsoftonline.com/{Directory (tenant) ID}/oauth2/v2.0/authorize",
"tokenUrl": "https://login.microsoftonline.com/{Directory (tenant) ID}/oauth2/v2.0/token",
"clientID": "{Application (client) ID}",
"scope": "openid offline_access {scope}"
}

 

truffle/html/authResult.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>SIMBAChain Sign In</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.message-container {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
margin: 0 30px;
}

.message {
font-weight: 300;
font-size: 1.3rem;
}

body.error .message {
display: none;
}

body.error .error-message {
display: block;
}

.error-message {
display: none;
font-weight: 300;
font-size: 1.3rem;
}

.error-text {
color: red;
font-size: 1rem;
}
</style>
</head>
<body>
<a class="branding" href="https://www.simbachain.com/">
SIMBAChain
</a>
<div class="message-container">
<div class="message">
You are signed in now and can close this page.
</div>
<div class="error-message">
An error occurred while signing in:
<div class="error-text"></div>
</div>
</div>
<script>
const search = window.location.search;
const error = (/[?&^]error=([^&]+)/.exec(search) || [])[1];
if (error) {
document.querySelector('.error-text').textContent = atob(decodeURIComponent(error));
document.querySelector('body').classList.add('error');
}
</script>
</body>
</html>

 

truffle/package-lock.json

https://github.com/SIMBAChain/truffle/blob/main/package-lock.json

 

truffle/package.json

{
    "name": "@simbachain/truffle",
    "version": "1.0.4",
    "description": "Truffle Plugin for SIMBAChain",
    "main": "build/main/index.js",
    "typings": "build/main/index.d.ts",
    "module": "build/module/index.js",
    "repository": "https://github.com/simmbachain/truffle",
    "license": "MIT",
    "keywords": [
        "simbachain",
        "truffle",
        "blockchain",
        "ethereum"
    ],
    "scripts": {
        "describe": "npm-scripts-info",
        "build": "run-s clean build:run",
        "build:run": "run-p build:main build:module",
        "build:main": "tsc -p tsconfig.json",
        "build:module": "tsc -p tsconfig.module.json",
        "fix": "run-s fix:*",
        "fix:prettier": "prettier \"src/**/*.ts\" --write",
        "fix:eslint": "eslint --fix --ext .ts -c .eslintrc.js \"src/**/*.ts\"",
        "test": "run-s build test:*",
        "test:lint": "eslint --ext .ts -c .eslintrc.js \"src/**/*.ts\" && prettier \"src/**/*.ts\" --list-different",
        "test:unit": "nyc --silent ava",
        "watch": "run-s clean build:main && run-p \"build:main -- -w\" \"test:unit -- --watch\"",
        "cov": "run-s build test:unit cov:html && open-cli coverage/index.html",
        "cov:html": "nyc report --reporter=html",
        "cov:send": "nyc report --reporter=lcov && codecov",
        "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
        "doc": "run-s doc:html && open-cli build-docs/docs/index.html",
        "doc:html": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs",
        "doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
        "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
        "version": "standard-version",
        "reset": "git clean -dfx && git reset --hard && npm i",
        "clean": "trash build test",
        "prepare-release": "run-s reset doc:html version doc:publish build:run"
    },
    "scripts-info": {
        "info": "Display information about the package scripts",
        "build": "Clean and rebuild the project",
        "fix": "Try to automatically fix any linting problems",
        "test": "Lint and unit test the project",
        "watch": "Watch and rebuild the project on save, then rerun relevant tests",
        "cov": "Rebuild, run tests, then create and open the coverage report",
        "doc": "Generate HTML API documentation and open it in a browser",
        "doc:json": "Generate API documentation in typedoc JSON format",
        "version": "Bump package.json version, update CHANGELOG.md, tag release",
        "reset": "Delete all untracked files and reset the repo to the last commit",
        "prepare-release": "One-step: clean, build, test, publish docs, and prep a release"
    },
    "engines": {
        "node": ">=10"
    },
    "dependencies": {
        "@truffle/config": "^1.2.33",
        "@types/configstore": "^4.0.0",
        "@types/crypto-js": "^3.1.44",
        "@types/npm-which": "^3.0.0",
        "@types/prompts": "^2.0.5",
        "@types/request-promise": "^4.1.46",
        "@types/trouter": "^3.1.0",
        "chalk": "^4.0.0",
        "configstore": "^5.0.1",
        "crypto-js": "^4.0.0",
        "crypto-random-string": "^3.2.0",
        "dts-gen": "^0.6.0",
        "npm-which": "^3.0.1",
        "polka": "^0.5.2",
        "prompts": "^2.3.2",
        "request-promise": "^4.2.5",
        "sha.js": "^2.4.11",
        "truffle": "^5.1.51",
        "winston": "^3.2.1",
        "yargs": "^15.3.1"
    },
    "devDependencies": {
        "@bitjson/npm-scripts-info": "^1.0.0",
        "@bitjson/typedoc": "^0.15.0-0",
        "@istanbuljs/nyc-config-typescript": "^0.1.3",
        "@types/sinon": "^7.5.2",
        "@types/yargs": "^15.0.4",
        "@typescript-eslint/eslint-plugin": "^2.25.0",
        "@typescript-eslint/eslint-plugin-tslint": "^2.25.0",
        "@typescript-eslint/parser": "^2.25.0",
        "ava": "^3.13.0",
        "codecov": "^3.5.0",
        "cz-conventional-changelog": "^2.1.0",
        "eslint": "^6.8.0",
        "eslint-config-prettier": "^6.10.1",
        "eslint-plugin-ava": "^10.2.0",
        "eslint-plugin-import": "^2.20.1",
        "eslint-plugin-prefer-arrow": "^1.1.7",
        "eslint-plugin-prettier": "^3.1.2",
        "gh-pages": "^2.0.1",
        "npm-run-all": "^4.1.5",
        "nyc": "^14.1.1",
        "open-cli": "^6.0.1",
        "prettier": "^1.19.1",
        "sinon": "^9.0.1",
        "standard-version": "^9.0.0",
        "trash-cli": "^3.0.0",
        "ts-node": "^9.0.0",
        "typescript": "^3.9.7"
    },
    "ava": {
        "failFast": true,
        "extensions": [
            "ts"
        ],
        "require": [
            "ts-node/register"
        ]
    },
    "config": {
        "commitizen": {
            "path": "cz-conventional-changelog"
        }
    },
    "prettier": {
        "quoteProps": "preserve",
        "semi": true,
        "trailingComma": "all",
        "singleQuote": true,
        "printWidth": 120,
        "tabWidth": 4,
        "endOfLine": "auto",
        "bracketSpacing": true,
        "arrowParens": "always",
        "parser": "typescript"
    },
    "nyc": {
        "extends": "@istanbuljs/nyc-config-typescript",
        "exclude": [
            "**/*.spec.js"
        ]
    }
}

 

truffle/truffle-plugin-simbachain.code-workspace

{
    "folders": [
        {
            "path": "."
        }
    ],
    "settings": {}
}

 

truffle/truffle-plugin.json

{
  "commands": {
    "simba": "index.js"
  }
}

 

truffle/tsconfig.json

{
  "compilerOptions": {
    "resolveJsonModule": true,
    "target": "es2017",
    "outDir": "build/main",
    "rootDir": "src",
    "moduleResolution": "node",
    "module": "commonjs",
    "declaration": true,
    "inlineSourceMap": true,
    "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
    "strict": true /* Enable all strict type-checking options. */,
    /* Strict Type-Checking Options */
    // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
    // "strictNullChecks": true /* Enable strict null checks. */,
    // "strictFunctionTypes": true /* Enable strict checking of function types. */,
    // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
    // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
    // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
    /* Additional Checks */
    "noUnusedLocals": true /* Report errors on unused locals. */,
    "noUnusedParameters": true /* Report errors on unused parameters. */,
    "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
    "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
    /* Debugging Options */
    "traceResolution": false /* Report module resolution log messages. */,
    "listEmittedFiles": false /* Print names of generated files part of the compilation. */,
    "listFiles": false /* Print names of files part of the compilation. */,
    "pretty": true /* Stylize errors and messages using color and context. */,
    /* Experimental Options */
    // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
    // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
    "lib": [
      "es2017"
    ],
    "types": [
      "node"
    ],
    "typeRoots": [
      "src/types",
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules/**"
  ],
  "compileOnSave": false
}

 

truffle/tsconfig.module.json

{
  "extends": "./tsconfig",
  "compilerOptions": {
    "target": "esnext",
    "outDir": "build/module",
    "module": "esnext"
  },
  "exclude": ["node_modules/**"]
}

 

SIMBA Truffle Integration

Overview

The SIMBA Truffle integration enables interaction with your SIMBA Enterprise Platform Instance from inside your VS Code development environment.

The SIMBA Enterprise Platform API supports contract creation and compilation from code or metadata and contract deployment of compiled Solidity contracts. The typical contract creation flow from the SIMBA UI is a low code/no code path in which contract metadata is graphically created in the Smart Contract Designer UI and then saved and compiled to Solidity. Subsequently the contract is deployed to an available blockchain. Additionally code can be directly edited and compiled in the Smart Contract Designer UI. However, this does not provide the developer with all the tools they are used to such as version control and an IDE.

The SIMBA Truffle integration allows Solidity contracts to be developed locally using state of the art blockchain development tools. The flow for the developer fits in with their typical development pipeline. Contracts and applications can be synchronised with an enterprise SIMBA deployment and loaded into VS Code. Once in VS Code, contracts can be developed, compiled and tested using Truffle tooling. Finally they can be deployed directly to a SIMBA enterprise instance. SIMBA receives and handles the Truffle metadata for sets of compiled contracts and deploys them to the blockchains that the enterprise deployment is linked to.

The developer can now enjoy all the goodness of SIMBA’s custom auto generated REST API for the contracts, enterprise infrastructure and scalability and advanced search capabilities! Prerequisites

You should have a SIMBA Enterprise Platform Instance to communicate with. Additionally you must have a least one contract application created in the instance. To create an application, open your browser, navigate to your instance and log in using your SIMBA user account. Click on your organization -> Applications and then click on the "Add" button on the bottom right corner of the page. Follow the on screen instructions to create your application.

Installation

To install the truffle plugin follow these steps.

Install the plugin from NPM.

$ npm install --save-dev @simbachain/truffle

Add the SIMBA plugin to the truffle plugins section in your truffle config.

{ 
... rest of truffle-config
plugins: [
"@simbachain/truffle"
]
}

Run the following command to ensure the plugin installed correctly.

$ truffle run simba --help

You should see a message similar to the below output:

Usage on the Simbachain plugin for Truffle

Commands:
truffle run simba login log in to SIMBAChain SCaaS
truffle run simba logout log out of SIMBAChain SCaaS
truffle run simba export export the project to SIMBAChain SCaaS
truffle run simba deploy deploy the project to SIMBAChain SCaaS
truffle run simba contract <command> Manage contracts

Options:
--help Show help [boolean]

Project Settings

In order to let the plugin know where your SIMBA Enterprise Platform is, create a simba.json file at the root of your project. Add the URL to the file in this form (See here if you use Azure AD):

{
"baseUrl": "https://my-sep.example.com/v2/",
"authorizeUrl": "https://my-auth.example.com/oauth2/v2.0/authorize",
"tokenUrl": "https://my-auth.example.com/oauth2/v2.0/token",
"clientID": "abc123",
"scope": "api://abc123/scaas.access"
}

Once done, from the command line, at the project root, run truffle run simba login to log into your SIMBA Enterprise Platform.

Contract Compilation

Most of the work is done by the base truffle CLI. Please see the truffle documentation to get a full explanation on how truffle compiles smart contracts. Briefly, you will need to write your smart contracts and save them in the <project folder>/contracts/ folder and then run the following command to compile your smart contract:

$ truffle compile

You should see a message similar to the output:

Compiling your contracts...
===========================
> Compiling ./contracts/FishTracker.sol
> Artifacts written to /Users/abrinckman/dev/truffle/plugin-test/build/contracts
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang

Contract Deployment

To deploy your contract to your SIMBA Enterprise Platform instance, create an application if you need to by following the instructions described in the ‘Prerequisites’ section above.

Next, in your terminal, use the truffle plugin to log into your SIMBA account:

$ truffle run simba login

Click the link to authenticate with the SIMBA platform and to authorize the plugin to make requests to the platform on your behalf. Once logged in, select the organization and the application you just created. You should see a message similar to this:

Logged In!
✔ Please pick an organisation › org-1
✔ Please pick an application › My Application
simba login: Logged in to org-1

Now that you have authorized the plugin to make requests to the SIMBA Platform, you are ready to export and deploy your contract. To export your contract, type the following command:

$ truffle run simba export

Follow the onscreen prompts to select the contract you want to export the SIMBA platform. For example:

? Please select your primary contract › - Use arrow-keys. Return to submit.
Application
Car
Coffee
❯ FishTracker

You should see a message similar to the following if the export was successful:

✔ Please select your primary contract › FishTracker
simba export: Sending to SIMBAChain SCaaS
simba export: Saved to Contract Design ID e4df3d92-786c-43b1-8634-5565a813c92f

To ensure the contract was uploaded to the SIMBA platform, open the SIMBA platform in a browser, log into the organization you exported the contract to and click on "Contracts". You should see your newly uploaded contract among the list of contracts.

Now that you have successfully exported your contract, you are ready to deploy the contract to the application. Type the following command to deploy your contract to the application:

$ truffle run simba deploy

Follow the onscreen prompts to choose an API name and the blockchain to which you want to deploy your contract. If successfully deployed, you should see a message similar to this:

✔ Please choose an API name [^[w-]*$] … Fish
✔ Please choose the blockchain to deploy to. › Ganache
✔ Please choose the storage to use. › Local Storage (Test)
✔ Please enter any arguments for the contract as a JSON dictionary. …
simba deploy: Deploying your app to SIMBAChain SCaaS
simba deploy: Contract deployment ID 18b00ec3-3e64-4f16-bebc-157551dd26cb
simba deploy: Your contract deployment is executing...
simba deploy: Your contract was deployed to 0x8ce1560537E3db66AF263b029Ba497559cEc7171

That’s it! You’re done. Now you can open the platform in the browser, navigate to your application and see your deployed contract. From here, you can now take advantage of all the same features provided by the platform. You will see that the contract has its own RESTful API, explorer, and GraphQL interface which can be used to query transactions made to the contract.