From 2115ffe2993a6c251b2a69f5454482d6f3a564b2 Mon Sep 17 00:00:00 2001 From: Todd Fleming Date: Tue, 2 Oct 2018 09:58:09 -0400 Subject: [PATCH 01/37] Allow greator control over Bytes serialization --- src/eosjs2-serialize.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/eosjs2-serialize.ts b/src/eosjs2-serialize.ts index b9d85065c..e2eb33c36 100644 --- a/src/eosjs2-serialize.ts +++ b/src/eosjs2-serialize.ts @@ -21,10 +21,21 @@ export interface Field { type: Type; } +/** Options for serialize() and deserialize() */ +export interface SerializerOptions { + bytesAsUint8Array?: boolean; +} + /** State for serialize() and deserialize() */ export class SerializerState { + public options: SerializerOptions; + /** Have any binary extensions been skipped? */ public skippedBinaryExtension = false; + + constructor(options: SerializerOptions = {}) { + this.options = options; + } } /** A type in an abi */ @@ -149,7 +160,7 @@ export class SerialBuffer { /** Return data with excess storage trimmed away */ public asUint8Array() { - return new Uint8Array(this.array.buffer, 0, this.length); + return new Uint8Array(this.array.buffer, this.array.byteOffset, this.length); } /** Append bytes */ @@ -185,7 +196,7 @@ export class SerialBuffer { if (this.readPos + len > this.length) { throw new Error("Read past end of buffer"); } - const result = new Uint8Array(this.array.buffer, this.readPos, len); + const result = new Uint8Array(this.array.buffer, this.array.byteOffset + this.readPos, len); this.readPos += len; return result; } @@ -858,8 +869,20 @@ export function createInitialTypes(): Map { bytes: createType({ name: "bytes", - serialize(buffer: SerialBuffer, data: string) { buffer.pushBytes(hexToUint8Array(data)); }, - deserialize(buffer: SerialBuffer) { return arrayToHex(buffer.getBytes()); }, + serialize(buffer: SerialBuffer, data: string | Uint8Array | number[]) { + if (data instanceof Uint8Array || Array.isArray(data)) { + buffer.pushBytes(data); + } else { + buffer.pushBytes(hexToUint8Array(data)); + } + }, + deserialize(buffer: SerialBuffer, state?: SerializerState) { + if (state.options.bytesAsUint8Array) { + return buffer.getBytes(); + } else { + return arrayToHex(buffer.getBytes()); + } + }, }), string: createType({ name: "string", From a73bf50b06e185f0a1165212095cc077689adf18 Mon Sep 17 00:00:00 2001 From: Boid-John Date: Thu, 4 Oct 2018 23:00:38 -0500 Subject: [PATCH 02/37] use native textEncoder/Decoder 'text-encoding' npm package is no longer maintained and the node native implementation is available since 8.3 https://nodejs.org/api/util.html#util_class_util_textencoder https://nodejs.org/api/util.html#util_class_util_textdecoder I would suggest that this package should automatically import and use these native functions when it detects that it's being run in node. Manual import should only be necessary if you need to override this. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a85a31ce..3a8728442 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Documentation can be found [here](https://eosio.github.io/eosjs) ```js const eosjs = require('eosjs'); const fetch = require('node-fetch'); // node only; not needed in browsers -const { TextDecoder, TextEncoder } = require('text-encoding'); // node, IE11 and IE Edge Browsers +const { TextDecoder, TextEncoder } = require('text-encoding'); // IE11 and IE Edge Browsers only +const {TextEncoder,TextDecoder} = require('util') // node only; native TextEncoder/Decoder ``` ### SignatureProvider @@ -107,4 +108,4 @@ After running `npm run build-web` or `yarn build-web`, the browser distribution 1. `npm run build-web` or `yarn build-web` 1. Open `test.html` in your browser of choice -*The integration tests assume that you have a local node for EOS set up at localhost:8000. The test.html file should run through 5 test cases with the final showing an exception on the screen for missing required TAPOS.* \ No newline at end of file +*The integration tests assume that you have a local node for EOS set up at localhost:8000. The test.html file should run through 5 test cases with the final showing an exception on the screen for missing required TAPOS.* From 0e5f0fb9ffccf5bfa3bf81c28331796d62ac764d Mon Sep 17 00:00:00 2001 From: Zhang Zengbo Date: Thu, 11 Oct 2018 11:57:33 +0800 Subject: [PATCH 03/37] remove polyfill from src --- .babelrc | 11 ++++++++++- package.json | 3 ++- src/index.ts | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.babelrc b/.babelrc index 684869769..f3a001138 100644 --- a/.babelrc +++ b/.babelrc @@ -6,5 +6,14 @@ } }], "stage-1" - ] + ], + "plugins": [ + [ + "transform-runtime", + { + "polyfill": false, + "regenerator": true + } + ] + ] } diff --git a/package.json b/package.json index f840ccebc..65e83940d 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,14 @@ }, "dependencies": { "@types/jest": "^23.3.1", - "babel-polyfill": "^6.26.0", + "babel-runtime": "^6.26.0", "eosjs-ecc": "^4.0.1", "text-encoding": "^0.6.4" }, "devDependencies": { "@types/node": "^10.3.1", "babel-cli": "^6.26.0", + "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-env": "^1.7.0", "babel-preset-stage-1": "^6.24.1", "jest": "^23.5.0", diff --git a/src/index.ts b/src/index.ts index 09ce77ef9..ad820ce18 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import "babel-polyfill"; import Api from "./eosjs-api"; import * as ApiInterfaces from "./eosjs-api-interfaces"; import JsonRpc from "./eosjs-jsonrpc"; From e08bd807283ff4a4bb5642b5095ae6b035b936c8 Mon Sep 17 00:00:00 2001 From: Terry Leung Date: Wed, 24 Oct 2018 16:52:29 +0800 Subject: [PATCH 04/37] Replace the way to access the DataView object with an anonymous function instead of a Proxy. Access it by calling the function directly. --- src/ripemd.es5.js | 14 ++++++-------- src/ripemd.js | 20 ++++++++------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/ripemd.es5.js b/src/ripemd.es5.js index dacd1f759..5ca80b180 100644 --- a/src/ripemd.es5.js +++ b/src/ripemd.es5.js @@ -328,12 +328,10 @@ var RIPEMD160 = function () { // The message after padding consists of t 16-word blocks that // are denoted with X_i[j], with 0≤i≤(t − 1) and 0≤j≤15. var X = new Array(t).fill(undefined).map(function (_, i) { - return new Proxy(new DataView(padded, i * block_size, block_size), { - get: function get(block_view, j) { - return block_view.getUint32(j * word_size, true // Little-endian - ); - } - }); + return function (j) { + return new DataView(padded, i * block_size, block_size).getUint32(j * word_size, true // Little-endian + ); + }; }); // The result of RIPEMD-160 is contained in five 32-bit words, @@ -360,7 +358,7 @@ var RIPEMD160 = function () { EP = E; for (var j = 0; j < 80; ++j) { // Left rounds - var _T = RIPEMD160.add_modulo32(RIPEMD160.rol32(RIPEMD160.add_modulo32(A, RIPEMD160.f(j, B, C, D), X[i][r[j]], RIPEMD160.K(j)), s[j]), E); + var _T = RIPEMD160.add_modulo32(RIPEMD160.rol32(RIPEMD160.add_modulo32(A, RIPEMD160.f(j, B, C, D), X[i](r[j]), RIPEMD160.K(j)), s[j]), E); A = E; E = D; D = RIPEMD160.rol32(C, 10); @@ -368,7 +366,7 @@ var RIPEMD160 = function () { B = _T; // Right rounds - _T = RIPEMD160.add_modulo32(RIPEMD160.rol32(RIPEMD160.add_modulo32(AP, RIPEMD160.f(79 - j, BP, CP, DP), X[i][rP[j]], RIPEMD160.KP(j)), sP[j]), EP); + _T = RIPEMD160.add_modulo32(RIPEMD160.rol32(RIPEMD160.add_modulo32(AP, RIPEMD160.f(79 - j, BP, CP, DP), X[i](rP[j]), RIPEMD160.KP(j)), sP[j]), EP); AP = EP; EP = DP; DP = RIPEMD160.rol32(CP, 10); diff --git a/src/ripemd.js b/src/ripemd.js index 567115169..e2d14140a 100644 --- a/src/ripemd.js +++ b/src/ripemd.js @@ -379,18 +379,14 @@ Method #2 // are denoted with X_i[j], with 0≤i≤(t − 1) and 0≤j≤15. const X = (new Array(t)) .fill(undefined) - .map((_, i) => new Proxy( + .map((_, i) => j => ( new DataView( padded, i * block_size, block_size - ), { - get(block_view, j) - { - return block_view.getUint32( - j * word_size, - true // Little-endian - ); - } - })); + ).getUint32( + j * word_size, + true // Little-endian + ) + )); // The result of RIPEMD-160 is contained in five 32-bit words, // which form the internal state of the algorithm. The final @@ -416,7 +412,7 @@ Method #2 RIPEMD160.add_modulo32( A, RIPEMD160.f(j, B, C, D), - X[i][r[j]], + X[i](r[j]), RIPEMD160.K(j) ), s[j] @@ -440,7 +436,7 @@ Method #2 CP, DP ), - X[i][rP[j]], + X[i](rP[j]), RIPEMD160.KP(j) ), sP[j] From 01d3d7a82515c4543246a4df3f2a88e661910aa9 Mon Sep 17 00:00:00 2001 From: Mike Creque Date: Thu, 25 Oct 2018 13:21:03 -0400 Subject: [PATCH 05/37] deploys to npm on tag to HEAD/master --- .travis.yml | 10 +++++++- scripts/is_latest.sh | 23 ++++++++++++++++++ scripts/publish.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100755 scripts/is_latest.sh create mode 100755 scripts/publish.sh diff --git a/.travis.yml b/.travis.yml index 49f4f4afb..dfcb78ab1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,15 @@ node_js: - '10.0.0' before_install: - npm install -g typescript +before_script: + - source ./scripts/is_latest.sh script: - npm run lint - npm run test - +deploy: + provider: script + script: + - ./scripts/publish.sh + on: + tags: true + condition: $TRAVIS_IS_LATEST_TAG = true # sourced from ./scripts/is_latest.sh \ No newline at end of file diff --git a/scripts/is_latest.sh b/scripts/is_latest.sh new file mode 100755 index 000000000..539542747 --- /dev/null +++ b/scripts/is_latest.sh @@ -0,0 +1,23 @@ +is_latest=false; + +current_commit="$(git rev-parse HEAD)"; +tags="$(git tag --sort=-creatordate)"; + +IFS='\n' read -ra arry <<< "$tags" + +latest_tag="${arry[0]}" + +if [ "$latest_tag" == "" ]; then + latest_tag="v0.0.0"; +else + tag_commit="$(git rev-list -n 1 ${latest_tag})"; + if [ "$tag_commit" = "$current_commit" ]; then + is_latest=true; + fi +fi + +echo "tag_commit: ${tag_commit}"; +echo "current_commit: ${current_commit}"; +echo "is_latest: ${is_latest}"; + +export TRAVIS_IS_LATEST_TAG="$is_latest" \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 000000000..21dc01c6d --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,57 @@ + +#!/bin/sh + +setup_git() { + # Set the user name and email to match the API token holder + # This will make sure the git commits will have the correct photo + # and the user gets the credit for a checkin + git config --global user.email "devops@block.one" + git config --global user.name "blockone-devops" + git config --global push.default matching + + # Get the credentials from a file + git config credential.helper "store --file=.git/credentials" + + # This associates the API Key with the account + echo "https://${GITHUB_API_KEY}:@github.com" > .git/credentials +} + +make_version() { + # Make sure that the workspace is clean + # It could be "dirty" if + # 1. package-lock.json is not aligned with package.json + # 2. npm install is run + git checkout -- . + + # Echo the status to the log so that we can see it is OK + git status + + # Run the deploy build and increment the package versions + # %s is the placeholder for the created tag + npm version -no-git-tag-version $TRAVIS_TAG +} + +upload_files() { + git commit -a -m "Updating version [skip ci]" + + # This make sure the current work area is pushed to the tip of the current branch + git push origin HEAD:master +} + +echo "Running on tag ${TRAVIS_TAG}, branch ${TRAVIS_BRANCH}": + +echo "Setting up git" +setup_git + +echo "Creating new version" + +make_version + +echo "Pushing to git" +upload_files + +echo "Publish to NPM" + +cp .npmrc.template $HOME/.npmrc +npm install +npm publish \ No newline at end of file From 700c43a3ee4036bc586ad245a7886624a84370b8 Mon Sep 17 00:00:00 2001 From: Mike Creque Date: Thu, 25 Oct 2018 16:30:49 -0400 Subject: [PATCH 06/37] includes template for npmrc --- .npmrc.template | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc.template diff --git a/.npmrc.template b/.npmrc.template new file mode 100644 index 000000000..2346004aa --- /dev/null +++ b/.npmrc.template @@ -0,0 +1 @@ +//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN} \ No newline at end of file From 01b70fba2bacaa0338f370828f8a28c80d0f5ac3 Mon Sep 17 00:00:00 2001 From: Ihor Peresunko Date: Thu, 25 Oct 2018 23:49:31 +0300 Subject: [PATCH 07/37] added secondary key support for get_table_rows #412 --- src/eosjs-jsonrpc.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/eosjs-jsonrpc.ts b/src/eosjs-jsonrpc.ts index e09743b66..fcceabdbc 100644 --- a/src/eosjs-jsonrpc.ts +++ b/src/eosjs-jsonrpc.ts @@ -141,7 +141,10 @@ export default class JsonRpc implements AuthorityProvider, AbiProvider { table_key = "", lower_bound = "", upper_bound = "", - limit = 10 }: any): Promise { + index_position = 1, + key_type = "", + limit = 10, + }: any): Promise { return await this.fetch( "/v1/chain/get_table_rows", { json, @@ -151,6 +154,8 @@ export default class JsonRpc implements AuthorityProvider, AbiProvider { table_key, lower_bound, upper_bound, + index_position, + key_type, limit, }); } From 99822c5f61302b5fb114830e788c81d4eb3454e7 Mon Sep 17 00:00:00 2001 From: Ihor Peresunko Date: Fri, 26 Oct 2018 00:14:31 +0300 Subject: [PATCH 08/37] fixed tests --- src/tests/eosjs-jsonrpc.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tests/eosjs-jsonrpc.test.ts b/src/tests/eosjs-jsonrpc.test.ts index a7c2bf7ab..e525ac041 100644 --- a/src/tests/eosjs-jsonrpc.test.ts +++ b/src/tests/eosjs-jsonrpc.test.ts @@ -351,6 +351,8 @@ describe("JSON RPC", () => { const lowerBound = "zero"; const upperBound = "five"; const limit = 20; + const indexPosition = 1; + const keyType = "str"; const expReturn = { data: "12345" }; const callParams = { json, @@ -360,6 +362,8 @@ describe("JSON RPC", () => { table_key: tableKey, lower_bound: lowerBound, upper_bound: upperBound, + index_position: indexPosition, + key_type: keyType, limit, }; const expParams = { @@ -385,6 +389,8 @@ describe("JSON RPC", () => { const lowerBound = ""; const upperBound = ""; const limit = 10; + const indexPosition = 1; + const keyType = ""; const expReturn = { data: "12345" }; const callParams = { code, @@ -400,6 +406,8 @@ describe("JSON RPC", () => { table_key: tableKey, lower_bound: lowerBound, upper_bound: upperBound, + index_position: indexPosition, + key_type: keyType, limit, }), method: "POST", From bd34f9bc2c28ab9702982c4e72661b529fbb032d Mon Sep 17 00:00:00 2001 From: Brandon Fancher Date: Fri, 26 Oct 2018 10:12:03 -0400 Subject: [PATCH 09/37] Allow signature providers to modify transactions. --- src/eosjs-api-interfaces.ts | 4 ++-- src/eosjs-api.ts | 3 +-- src/eosjs-jssig.ts | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/eosjs-api-interfaces.ts b/src/eosjs-api-interfaces.ts index 1721ea52e..cd07a7a4b 100644 --- a/src/eosjs-api-interfaces.ts +++ b/src/eosjs-api-interfaces.ts @@ -1,6 +1,6 @@ // copyright defined in eosjs/LICENSE.txt -import { Abi } from "./eosjs-rpc-interfaces"; +import { Abi, PushTransactionArgs } from "./eosjs-rpc-interfaces"; /** Arguments to `getRequiredKeys` */ export interface AuthorityProviderArgs { @@ -63,5 +63,5 @@ export interface SignatureProvider { getAvailableKeys: () => Promise; /** Sign a transaction */ - sign: (args: SignatureProviderArgs) => Promise; + sign: (args: SignatureProviderArgs) => Promise; } diff --git a/src/eosjs-api.ts b/src/eosjs-api.ts index 10a4c1c1a..4b98cf687 100644 --- a/src/eosjs-api.ts +++ b/src/eosjs-api.ts @@ -238,13 +238,12 @@ export default class Api { const serializedTransaction = this.serializeTransaction(transaction); const availableKeys = await this.signatureProvider.getAvailableKeys(); const requiredKeys = await this.authorityProvider.getRequiredKeys({ transaction, availableKeys }); - const signatures = await this.signatureProvider.sign({ + const pushTransactionArgs = await this.signatureProvider.sign({ chainId: this.chainId, requiredKeys, serializedTransaction, abis, }); - const pushTransactionArgs = { signatures, serializedTransaction }; if (broadcast) { return this.pushSignedTransaction(pushTransactionArgs); } diff --git a/src/eosjs-jssig.ts b/src/eosjs-jssig.ts index 804bd2441..a47d3c782 100644 --- a/src/eosjs-jssig.ts +++ b/src/eosjs-jssig.ts @@ -34,8 +34,9 @@ export default class JsSignatureProvider implements SignatureProvider { const signBuf = Buffer.concat([ new Buffer(chainId, "hex"), new Buffer(serializedTransaction), new Buffer(new Uint8Array(32)), ]); - return requiredKeys.map( + const signatures = requiredKeys.map( (pub) => ecc.Signature.sign(signBuf, this.keys.get(convertLegacyPublicKey(pub))).toString(), ); + return { signatures, serializedTransaction }; } } From 09b3280189e2d4db0ce8a08754edc9f811377c13 Mon Sep 17 00:00:00 2001 From: Brandon Fancher Date: Fri, 26 Oct 2018 10:12:20 -0400 Subject: [PATCH 10/37] Update signature provider test. --- src/tests/eosjs-jssig.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/eosjs-jssig.test.ts b/src/tests/eosjs-jssig.test.ts index e99ae79ca..acdc47265 100644 --- a/src/tests/eosjs-jssig.test.ts +++ b/src/tests/eosjs-jssig.test.ts @@ -34,9 +34,9 @@ describe("JsSignatureProvider", () => { ]); const abis: any[] = []; - const signatures = await provider.sign({ chainId, requiredKeys, serializedTransaction, abis }); + const signOutput = await provider.sign({ chainId, requiredKeys, serializedTransaction, abis }); expect(eccSignatureSign).toHaveBeenCalledTimes(2); - expect(signatures).toEqual([privateKeys[0], privateKeys[2]]); + expect(signOutput).toEqual({ signatures: [privateKeys[0], privateKeys[2]], serializedTransaction }); }); }); From 5745146cfcb806caafd1646f0e296393e1164625 Mon Sep 17 00:00:00 2001 From: Ricky Kung Date: Mon, 29 Oct 2018 16:11:30 +0800 Subject: [PATCH 11/37] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b82e313c1..111707fb6 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ try { } catch (e) { console.log('\nCaught exception: ' + e); if (e instanceof RpcError) - console.log(JSON.stringify(e.json, null, 2); + console.log(JSON.stringify(e.json, null, 2)); } ... ``` From d30d238f4ac4de0d882c15fa928073b6d1c239db Mon Sep 17 00:00:00 2001 From: Mike Creque Date: Wed, 31 Oct 2018 15:35:47 -0400 Subject: [PATCH 12/37] deploys eosjs web build to cdn --- .travis.yml | 39 +++++++++++++++++++++++++++++---------- package.json | 2 +- scripts/publish.sh | 4 ++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index dfcb78ab1..bf4f96846 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,37 @@ +env: + global: + CDN_BUCKET_NAME="eosio-eosjs" sudo: false language: node_js node_js: - - '10.0.0' + - '10.0.0' before_install: - - npm install -g typescript + - yarn global add typescript + - yarn global add webpack before_script: - source ./scripts/is_latest.sh script: - - npm run lint - - npm run test + - yarn run lint + - yarn run test + - yarn run build-web deploy: - provider: script - script: - - ./scripts/publish.sh - on: - tags: true - condition: $TRAVIS_IS_LATEST_TAG = true # sourced from ./scripts/is_latest.sh \ No newline at end of file + - provider: script + skip_cleanup: true + script: + - ./scripts/publish.sh + on: + tags: true + condition: $TRAVIS_IS_LATEST_TAG = true # sourced from ./scripts/is_latest.sh + - provider: s3 + skip_cleanup: true + access_key_id: $S3_USER_ID + secret_access_key: $S3_USER_SECRET + bucket: "${CDN_BUCKET_NAME}" + region: us-west-2 + local_dir: dist-web + upload-dir: $TRAVIS_TAG + on: + tags: true + condition: $TRAVIS_IS_LATEST_TAG = true # sourced from ./scripts/is_latest.sh +after_deploy: + - echo "CDN base url - https://${CDN_BUCKET_NAME}.s3.amazonaws.com/${TRAVIS_TAG}/" \ No newline at end of file diff --git a/package.json b/package.json index f840ccebc..b7027dbad 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Talk to eos API", "main": "dist/index.js", "scripts": { - "prepublish": "npm run build", + "prepare": "npm run build", "test": "jest", "lint": "tslint -c tslint.json src/**/*.ts", "lint-fix": "tslint -c tslint.json src/**/*.ts --fix", diff --git a/scripts/publish.sh b/scripts/publish.sh index 21dc01c6d..72f8bcc77 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -50,8 +50,8 @@ make_version echo "Pushing to git" upload_files -echo "Publish to NPM" +echo "Build and Publish to NPM" cp .npmrc.template $HOME/.npmrc -npm install + npm publish \ No newline at end of file From d997c9101919459f1d21a39833559da3fba28a98 Mon Sep 17 00:00:00 2001 From: Mike Creque Date: Thu, 1 Nov 2018 13:27:18 -0400 Subject: [PATCH 13/37] assigns beta tag to npm package for beta git tag --- scripts/publish.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/publish.sh b/scripts/publish.sh index 72f8bcc77..2b174aa71 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,5 +1,4 @@ - -#!/bin/sh +#!/bin/bash setup_git() { # Set the user name and email to match the API token holder @@ -54,4 +53,10 @@ echo "Build and Publish to NPM" cp .npmrc.template $HOME/.npmrc -npm publish \ No newline at end of file +if [[ "$TRAVIS_TAG" == *"-beta"* ]]; then + echo "Publishing with beta tag to npm" + npm publish --tag beta +else + echo "Publishing with latest tag to npm" + npm publish +fi \ No newline at end of file From 089cb371a9a71ff68f4ec09ba2fd995da0d849ad Mon Sep 17 00:00:00 2001 From: Randy Torres Date: Tue, 6 Nov 2018 12:50:34 -0800 Subject: [PATCH 14/37] Remove default signature provider from exports --- README.md | 8 ++++++-- src/index.ts | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 111707fb6..5eacece04 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,18 @@ Documentation can be found [here](https://eosio.github.io/eosjs) Importing using ES6 module syntax in the browser is supported if you have a transpiler, such as Babel. ```js -import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'eosjs'; +import { Api, JsonRpc, RpcError } from 'eosjs'; + +// If using default signature provider +import JsSignatureProvider from 'eosjs/dist/eosjs-jssig' ``` ### NodeJS Importing using commonJS syntax is supported by node out of the box. ```js -const { Api, JsonRpc, RpcError, JsSignatureProvider } = require('eosjs'); +const { Api, JsonRpc, RpcError } = require('eosjs'); +const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); const fetch = require('node-fetch'); // node only; not needed in browsers const { TextDecoder, TextEncoder } = require('text-encoding'); // IE11 and IE Edge Browsers only const {TextEncoder,TextDecoder} = require('util') // node only; native TextEncoder/Decoder diff --git a/src/index.ts b/src/index.ts index ad820ce18..baa07bf60 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,8 @@ import Api from "./eosjs-api"; import * as ApiInterfaces from "./eosjs-api-interfaces"; import JsonRpc from "./eosjs-jsonrpc"; -import JsSignatureProvider from "./eosjs-jssig"; import * as RpcInterfaces from "./eosjs-rpc-interfaces"; import RpcError from "./eosjs-rpcerror"; import * as Serialize from "./eosjs-serialize"; -export { Api, ApiInterfaces, JsonRpc, RpcInterfaces, RpcError, JsSignatureProvider, Serialize }; +export { Api, ApiInterfaces, JsonRpc, RpcInterfaces, RpcError, Serialize }; From 460f9d5e9ab50128eda68b6f2ba4112fe6fc8893 Mon Sep 17 00:00:00 2001 From: Pacien Boisson Date: Fri, 9 Nov 2018 16:13:44 -0800 Subject: [PATCH 15/37] Reading blockchain examples --- docs/2.-Transaction-Examples.md | 27 ++++++++-- docs/4.-Reading blockchain-Examples.md | 72 ++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 docs/4.-Reading blockchain-Examples.md diff --git a/docs/2.-Transaction-Examples.md b/docs/2.-Transaction-Examples.md index 4f1af17d8..6ae3eb6ce 100644 --- a/docs/2.-Transaction-Examples.md +++ b/docs/2.-Transaction-Examples.md @@ -1,4 +1,25 @@ -## Example: Buy ram +# Transactions + +To be able to send transactions and trigger actions on the blockchain, you must have an instance of `Api`. + +The signature provider must contains the private keys corresponsing to the actors and permissions of the actions. + +```javascript +const { Api, JsonRpc, JsSignatureProvider } = require('eosjs'); +const fetch = require('node-fetch'); // node only; not needed in browsers +const { TextDecoder, TextEncoder } = require('text-encoding'); // node, IE11 and IE Edge Browsers + +const privateKeys = [privateKey1]; + +const signatureProvider = new JsSignatureProvider(privateKeys); +const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch }); +const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); + +``` + +## Examples + +### Buy ram ```javascript const result = await api.transact({ @@ -21,7 +42,7 @@ const result = await api.transact({ }); ``` -## Example: Stake +### Stake ```javascript const result = await api.transact({ @@ -71,7 +92,7 @@ const result = await api.transact({ }); ``` -## Example: Create New Account (multiple actions) +### Create New Account (multiple actions) ```javascript const result = await api.transact({ diff --git a/docs/4.-Reading blockchain-Examples.md b/docs/4.-Reading blockchain-Examples.md new file mode 100644 index 000000000..6de85cd1a --- /dev/null +++ b/docs/4.-Reading blockchain-Examples.md @@ -0,0 +1,72 @@ +# Reading blockchain + +Reading blockchain state only requires an instance of `JsonRpc` connected to a node. + +```javascript +const {JsonRpc } = require('eosjs'); +const fetch = require('node-fetch'); // node only; not needed in browsers +const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch }); +``` + +## Examples + +### Token balances + +Get the first 10 token balances of account _testacc_. + +```javascript + +const resp = await rpc.get_table_rows({ + json: true, // Get the response as json + code: 'eosio.token', // Contract that we target + scope: 'testacc' // Account that owns the data + table: 'accounts' // Table name + limit: 10, // maximum number of rows that we want to get +}); + +console.log(resp.rows); + +``` +Output: + +```json +{ + "rows": [{ + "balance": "100.0000 HAK" + } + ], + "more": false +} +``` + +### Get by index + +Get one item in table by primary index + +```javascript + +const resp = await rpc.get_table_rows({ + json: true, // Get the response as json + code: 'contract', // Contract that we target + scope: 'contract' // Account that owns the data + table: 'profiles' // Table name + lower_bound: 'testacc' // Table primary key value + limit: 1, // Here we limit to 1 to get only the +}); + +console.log(resp.rows); + +``` +Output: + +```json +{ + "rows": [{ + "user": "testacc", + "age": 21, + "surname": "Martin" + } + ], + "more": false +} +``` From f4a393779aa0b873b36693e37f452bbdb41bdf5c Mon Sep 17 00:00:00 2001 From: Pacien Boisson Date: Fri, 9 Nov 2018 16:50:40 -0800 Subject: [PATCH 16/37] More examples --- docs/4.-Reading blockchain-Examples.md | 79 ++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/docs/4.-Reading blockchain-Examples.md b/docs/4.-Reading blockchain-Examples.md index 6de85cd1a..05a4553f7 100644 --- a/docs/4.-Reading blockchain-Examples.md +++ b/docs/4.-Reading blockchain-Examples.md @@ -10,12 +10,11 @@ const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch }); ## Examples -### Token balances +### Get table rows Get the first 10 token balances of account _testacc_. ```javascript - const resp = await rpc.get_table_rows({ json: true, // Get the response as json code: 'eosio.token', // Contract that we target @@ -25,7 +24,6 @@ const resp = await rpc.get_table_rows({ }); console.log(resp.rows); - ``` Output: @@ -39,23 +37,19 @@ Output: } ``` -### Get by index - -Get one item in table by primary index +### Get one row by index ```javascript - const resp = await rpc.get_table_rows({ json: true, // Get the response as json code: 'contract', // Contract that we target scope: 'contract' // Account that owns the data table: 'profiles' // Table name lower_bound: 'testacc' // Table primary key value - limit: 1, // Here we limit to 1 to get only the + limit: 1, // Here we limit to 1 to get only the + index_position: 1, // 1: primary index, 2: secondary index ... }); - console.log(resp.rows); - ``` Output: @@ -70,3 +64,68 @@ Output: "more": false } ``` + +### Get currency balance + +```javascript +console.log(await rpc.get_currency_balance('eosio.token', 'testacc', 'HAK')); +``` +Output: + +```json +[ '1000000000.0000 HAK' ] +``` + +### Get account info + +```javascript +console.log(await rpc.get_account('testacc')); +``` +Output: + +```json +{ account_name: 'testacc', + head_block_num: 1079, + head_block_time: '2018-11-10T00:45:53.500', + privileged: false, + last_code_update: '1970-01-01T00:00:00.000', + created: '2018-11-10T00:37:05.000', + ram_quota: -1, + net_weight: -1, + cpu_weight: -1, + net_limit: { used: -1, available: -1, max: -1 }, + cpu_limit: { used: -1, available: -1, max: -1 }, + ram_usage: 2724, + permissions: + [ { perm_name: 'active', parent: 'owner', required_auth: [Object] }, + { perm_name: 'owner', parent: '', required_auth: [Object] } ], + total_resources: null, + self_delegated_bandwidth: null, + refund_request: null, + voter_info: null } +``` + +### Get block + +```javascript +console.log(await rpc.get_block(1)); +``` +Output: + +```json +{ timestamp: '2018-06-01T12:00:00.000', + producer: '', + confirmed: 1, + previous: '0000000000000000000000000000000000000000000000000000000000000000', + transaction_mroot: '0000000000000000000000000000000000000000000000000000000000000000', + action_mroot: 'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f', + schedule_version: 0, + new_producers: null, + header_extensions: [], + producer_signature: 'SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne', + transactions: [], + block_extensions: [], + id: '00000001bcf2f448225d099685f14da76803028926af04d2607eafcf609c265c', + block_num: 1, + ref_block_prefix: 2517196066 } +``` From 65ac5aad94c8202faffb1e919aa10a20eedcd8f8 Mon Sep 17 00:00:00 2001 From: Pacien Boisson Date: Fri, 9 Nov 2018 16:52:35 -0800 Subject: [PATCH 17/37] fix json --- docs/4.-Reading blockchain-Examples.md | 70 +++++++++++++------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/docs/4.-Reading blockchain-Examples.md b/docs/4.-Reading blockchain-Examples.md index 05a4553f7..a1008f421 100644 --- a/docs/4.-Reading blockchain-Examples.md +++ b/docs/4.-Reading blockchain-Examples.md @@ -73,7 +73,7 @@ console.log(await rpc.get_currency_balance('eosio.token', 'testacc', 'HAK')); Output: ```json -[ '1000000000.0000 HAK' ] +[ "1000000000.0000 HAK" ] ``` ### Get account info @@ -84,25 +84,25 @@ console.log(await rpc.get_account('testacc')); Output: ```json -{ account_name: 'testacc', - head_block_num: 1079, - head_block_time: '2018-11-10T00:45:53.500', - privileged: false, - last_code_update: '1970-01-01T00:00:00.000', - created: '2018-11-10T00:37:05.000', - ram_quota: -1, - net_weight: -1, - cpu_weight: -1, - net_limit: { used: -1, available: -1, max: -1 }, - cpu_limit: { used: -1, available: -1, max: -1 }, - ram_usage: 2724, - permissions: - [ { perm_name: 'active', parent: 'owner', required_auth: [Object] }, - { perm_name: 'owner', parent: '', required_auth: [Object] } ], - total_resources: null, - self_delegated_bandwidth: null, - refund_request: null, - voter_info: null } +{ "account_name": "testacc", + "head_block_num": 1079, + "head_block_time": "2018-11-10T00:45:53.500", + "privileged": false, + "last_code_update": "1970-01-01T00:00:00.000", + "created": "2018-11-10T00:37:05.000", + "ram_quota": -1, + "net_weight": -1, + "cpu_weight": -1, + "net_limit": { used: -1, available: -1, max: -1 }, + "cpu_limit": { used: -1, available: -1, max: -1 }, + "ram_usage": 2724, + "permissions": + [ { "perm_name": "active", "parent": "owner", "required_auth": [] }, + { "perm_name": "owner", "parent": "", "required_auth": [] } ], + "total_resources": null, + "self_delegated_bandwidth": null, + "refund_request": null, + "voter_info": null } ``` ### Get block @@ -113,19 +113,19 @@ console.log(await rpc.get_block(1)); Output: ```json -{ timestamp: '2018-06-01T12:00:00.000', - producer: '', - confirmed: 1, - previous: '0000000000000000000000000000000000000000000000000000000000000000', - transaction_mroot: '0000000000000000000000000000000000000000000000000000000000000000', - action_mroot: 'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f', - schedule_version: 0, - new_producers: null, - header_extensions: [], - producer_signature: 'SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne', - transactions: [], - block_extensions: [], - id: '00000001bcf2f448225d099685f14da76803028926af04d2607eafcf609c265c', - block_num: 1, - ref_block_prefix: 2517196066 } +{ "timestamp": "2018-06-01T12:00:00.000", + "producer": "", + "confirmed": 1, + "previous": "0000000000000000000000000000000000000000000000000000000000000000", + "transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000", + "action_mroot": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", + "schedule_version": 0, + "new_producers": null, + "header_extensions": [], + "producer_signature": "SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne", + "transactions": [], + "block_extensions": [], + "id": "00000001bcf2f448225d099685f14da76803028926af04d2607eafcf609c265c", + "block_num": 1, + "ref_block_prefix": 2517196066 } ``` From d30b0321baf5c4ceaa5ebd1d943f629f8e5d28f7 Mon Sep 17 00:00:00 2001 From: Pacien Boisson Date: Fri, 9 Nov 2018 16:53:07 -0800 Subject: [PATCH 18/37] fix json --- docs/4.-Reading blockchain-Examples.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/4.-Reading blockchain-Examples.md b/docs/4.-Reading blockchain-Examples.md index a1008f421..ba20c4c23 100644 --- a/docs/4.-Reading blockchain-Examples.md +++ b/docs/4.-Reading blockchain-Examples.md @@ -93,8 +93,8 @@ Output: "ram_quota": -1, "net_weight": -1, "cpu_weight": -1, - "net_limit": { used: -1, available: -1, max: -1 }, - "cpu_limit": { used: -1, available: -1, max: -1 }, + "net_limit": { "used": -1, "available": -1, "max": -1 }, + "cpu_limit": { "used": -1, "available": -1, "max": -1 }, "ram_usage": 2724, "permissions": [ { "perm_name": "active", "parent": "owner", "required_auth": [] }, From 6b97a8c472e372663561c70f2eff668b316257a8 Mon Sep 17 00:00:00 2001 From: Pacien Boisson Date: Sun, 11 Nov 2018 15:54:23 -0800 Subject: [PATCH 19/37] fix secondary key filtering --- docs/4.-Reading blockchain-Examples.md | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/4.-Reading blockchain-Examples.md b/docs/4.-Reading blockchain-Examples.md index ba20c4c23..fd957a51f 100644 --- a/docs/4.-Reading blockchain-Examples.md +++ b/docs/4.-Reading blockchain-Examples.md @@ -47,7 +47,34 @@ const resp = await rpc.get_table_rows({ table: 'profiles' // Table name lower_bound: 'testacc' // Table primary key value limit: 1, // Here we limit to 1 to get only the - index_position: 1, // 1: primary index, 2: secondary index ... +}); +console.log(resp.rows); +``` +Output: + +```json +{ + "rows": [{ + "user": "testacc", + "age": 21, + "surname": "Martin" + } + ], + "more": false +} +``` + +### Get one row by secondary index + +```javascript +const resp = await rpc.get_table_rows({ + json: true, // Get the response as json + code: 'contract', // Contract that we target + scope: 'contract' // Account that owns the data + table: 'profiles' // Table name + table_key: 'age' // Table secondaray key name + lower_bound: 21 // Table secondary key value + limit: 1, // Here we limit to 1 to get only the }); console.log(resp.rows); ``` From 0faa97d37f4dee2a35930bcfde78ed842c1d5fec Mon Sep 17 00:00:00 2001 From: ehnawh Date: Mon, 12 Nov 2018 14:24:20 +0900 Subject: [PATCH 20/37] Add checking type of data to serializeStruct --- src/eosjs-serialize.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/eosjs-serialize.ts b/src/eosjs-serialize.ts index 8e0237b7c..b70ffc56c 100644 --- a/src/eosjs-serialize.ts +++ b/src/eosjs-serialize.ts @@ -616,6 +616,9 @@ function deserializeUnknown(buffer: SerialBuffer): SerialBuffer { function serializeStruct(this: Type, buffer: SerialBuffer, data: any, state = new SerializerState(), allowExtensions = true) { + if (typeof data !== "object") { + throw new Error("expected object containing data: " + JSON.stringify(data)); + } if (this.base) { this.base.serialize(buffer, data, state, allowExtensions); } From c890434cf693e9d9a46bc61cc00f46766c31a0f4 Mon Sep 17 00:00:00 2001 From: ehnawh Date: Wed, 14 Nov 2018 15:40:15 +0900 Subject: [PATCH 21/37] add selective sign parameter to transact function --- src/eosjs-api.ts | 25 +++++++++++++++---------- src/eosjs-rpc-interfaces.ts | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/eosjs-api.ts b/src/eosjs-api.ts index 4b98cf687..1b42e6c3e 100644 --- a/src/eosjs-api.ts +++ b/src/eosjs-api.ts @@ -212,8 +212,8 @@ export default class Api { * use it as a reference for TAPoS, and expire the transaction `expireSeconds` after that block's time. * @returns node response if `broadcast`, `{signatures, serializedTransaction}` if `!broadcast` */ - public async transact(transaction: any, { broadcast = true, blocksBehind, expireSeconds }: - { broadcast?: boolean; blocksBehind?: number; expireSeconds?: number; } = {}): Promise { + public async transact(transaction: any, { broadcast = true, sign = true, blocksBehind, expireSeconds }: + { broadcast?: boolean; sign?: boolean; blocksBehind?: number; expireSeconds?: number; } = {}): Promise { let info: GetInfoResult; if (!this.chainId) { @@ -236,14 +236,19 @@ export default class Api { const abis: BinaryAbi[] = await this.getTransactionAbis(transaction); transaction = { ...transaction, actions: await this.serializeActions(transaction.actions) }; const serializedTransaction = this.serializeTransaction(transaction); - const availableKeys = await this.signatureProvider.getAvailableKeys(); - const requiredKeys = await this.authorityProvider.getRequiredKeys({ transaction, availableKeys }); - const pushTransactionArgs = await this.signatureProvider.sign({ - chainId: this.chainId, - requiredKeys, - serializedTransaction, - abis, - }); + + let pushTransactionArgs: PushTransactionArgs = { serializedTransaction }; + + if (sign) { + const availableKeys = await this.signatureProvider.getAvailableKeys(); + const requiredKeys = await this.authorityProvider.getRequiredKeys({ transaction, availableKeys }); + const pushTransactionArgs = await this.signatureProvider.sign({ + chainId: this.chainId, + requiredKeys, + serializedTransaction, + abis, + }); + } if (broadcast) { return this.pushSignedTransaction(pushTransactionArgs); } diff --git a/src/eosjs-rpc-interfaces.ts b/src/eosjs-rpc-interfaces.ts index 1b9d7b257..2b1092fc1 100644 --- a/src/eosjs-rpc-interfaces.ts +++ b/src/eosjs-rpc-interfaces.ts @@ -75,6 +75,6 @@ export interface GetRawCodeAndAbiResult { /** Arguments for `push_transaction` */ export interface PushTransactionArgs { - signatures: string[]; + signatures?: string[]; serializedTransaction: Uint8Array; } From 4a07b80162ee26b7eabd0a59ac2034a28dd65965 Mon Sep 17 00:00:00 2001 From: ehnawh Date: Wed, 14 Nov 2018 15:53:44 +0900 Subject: [PATCH 22/37] add comment about sign to transact function --- src/eosjs-api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/eosjs-api.ts b/src/eosjs-api.ts index 1b42e6c3e..09fdda841 100644 --- a/src/eosjs-api.ts +++ b/src/eosjs-api.ts @@ -207,6 +207,7 @@ export default class Api { * * Named Parameters: * * `broadcast`: broadcast this transaction? + * * `sign`: sign this transaction? * * If both `blocksBehind` and `expireSeconds` are present, * then fetch the block which is `blocksBehind` behind head block, * use it as a reference for TAPoS, and expire the transaction `expireSeconds` after that block's time. From 5c46300b0dce5d9771404e0398bb46aa64ab1619 Mon Sep 17 00:00:00 2001 From: ehnawh Date: Sun, 18 Nov 2018 18:37:34 +0900 Subject: [PATCH 23/37] fix bug and remove extra empty lines --- src/eosjs-api.ts | 5 ++--- src/eosjs-rpc-interfaces.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/eosjs-api.ts b/src/eosjs-api.ts index 09fdda841..db2b9617d 100644 --- a/src/eosjs-api.ts +++ b/src/eosjs-api.ts @@ -237,13 +237,12 @@ export default class Api { const abis: BinaryAbi[] = await this.getTransactionAbis(transaction); transaction = { ...transaction, actions: await this.serializeActions(transaction.actions) }; const serializedTransaction = this.serializeTransaction(transaction); + let pushTransactionArgs: PushTransactionArgs = { serializedTransaction, signatures: [] }; - let pushTransactionArgs: PushTransactionArgs = { serializedTransaction }; - if (sign) { const availableKeys = await this.signatureProvider.getAvailableKeys(); const requiredKeys = await this.authorityProvider.getRequiredKeys({ transaction, availableKeys }); - const pushTransactionArgs = await this.signatureProvider.sign({ + pushTransactionArgs = await this.signatureProvider.sign({ chainId: this.chainId, requiredKeys, serializedTransaction, diff --git a/src/eosjs-rpc-interfaces.ts b/src/eosjs-rpc-interfaces.ts index 2b1092fc1..1b9d7b257 100644 --- a/src/eosjs-rpc-interfaces.ts +++ b/src/eosjs-rpc-interfaces.ts @@ -75,6 +75,6 @@ export interface GetRawCodeAndAbiResult { /** Arguments for `push_transaction` */ export interface PushTransactionArgs { - signatures?: string[]; + signatures: string[]; serializedTransaction: Uint8Array; } From 54344c37febe84273d293ceccab83dd585aaba2d Mon Sep 17 00:00:00 2001 From: Mike Creque Date: Mon, 26 Nov 2018 10:37:57 -0500 Subject: [PATCH 24/37] publish develop branch with edge tag --- .travis.yml | 22 +--------------------- scripts/publish.sh | 17 +++++------------ 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf4f96846..8a31824d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,3 @@ -env: - global: - CDN_BUCKET_NAME="eosio-eosjs" sudo: false language: node_js node_js: @@ -8,30 +5,13 @@ node_js: before_install: - yarn global add typescript - yarn global add webpack -before_script: - - source ./scripts/is_latest.sh script: - yarn run lint - yarn run test - - yarn run build-web deploy: - provider: script skip_cleanup: true script: - ./scripts/publish.sh on: - tags: true - condition: $TRAVIS_IS_LATEST_TAG = true # sourced from ./scripts/is_latest.sh - - provider: s3 - skip_cleanup: true - access_key_id: $S3_USER_ID - secret_access_key: $S3_USER_SECRET - bucket: "${CDN_BUCKET_NAME}" - region: us-west-2 - local_dir: dist-web - upload-dir: $TRAVIS_TAG - on: - tags: true - condition: $TRAVIS_IS_LATEST_TAG = true # sourced from ./scripts/is_latest.sh -after_deploy: - - echo "CDN base url - https://${CDN_BUCKET_NAME}.s3.amazonaws.com/${TRAVIS_TAG}/" \ No newline at end of file + branch: develop \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh index 2b174aa71..e18b6390b 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -26,18 +26,17 @@ make_version() { git status # Run the deploy build and increment the package versions - # %s is the placeholder for the created tag - npm version -no-git-tag-version $TRAVIS_TAG + npm version -no-git-tag-version prerelease } upload_files() { git commit -a -m "Updating version [skip ci]" # This make sure the current work area is pushed to the tip of the current branch - git push origin HEAD:master + git push origin HEAD:${TRAVIS_BRANCH} } -echo "Running on tag ${TRAVIS_TAG}, branch ${TRAVIS_BRANCH}": +echo "Running on branch ${TRAVIS_BRANCH}": echo "Setting up git" setup_git @@ -49,14 +48,8 @@ make_version echo "Pushing to git" upload_files -echo "Build and Publish to NPM" +echo "Publish to NPM" cp .npmrc.template $HOME/.npmrc -if [[ "$TRAVIS_TAG" == *"-beta"* ]]; then - echo "Publishing with beta tag to npm" - npm publish --tag beta -else - echo "Publishing with latest tag to npm" - npm publish -fi \ No newline at end of file +npm publish --tag edge \ No newline at end of file From 0f26741f8dc9100a05cd4fab4cbf9b2e86136c75 Mon Sep 17 00:00:00 2001 From: blockone-devops Date: Mon, 26 Nov 2018 19:04:43 +0000 Subject: [PATCH 25/37] Updating version [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85fe7efc6..c2ae55dd8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eosjs", - "version": "20.0.0-beta2", + "version": "20.0.0-beta2.0", "description": "Talk to eos API", "main": "dist/index.js", "scripts": { From 69493f0b2277b558ed8a4451d04e2ee391343018 Mon Sep 17 00:00:00 2001 From: blockone-devops Date: Tue, 27 Nov 2018 16:08:06 +0000 Subject: [PATCH 26/37] Updating version [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2ae55dd8..c26b1b2b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eosjs", - "version": "20.0.0-beta2.0", + "version": "20.0.0-beta2.1", "description": "Talk to eos API", "main": "dist/index.js", "scripts": { From e605662117452734ec9b9fec94ba005c6d08012e Mon Sep 17 00:00:00 2001 From: Mike Creque Date: Wed, 28 Nov 2018 10:12:48 -0500 Subject: [PATCH 27/37] removes deployment --- .travis.yml | 7 ------- package.json | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a31824d1..ec90df6a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,3 @@ before_install: script: - yarn run lint - yarn run test -deploy: - - provider: script - skip_cleanup: true - script: - - ./scripts/publish.sh - on: - branch: develop \ No newline at end of file diff --git a/package.json b/package.json index c26b1b2b1..85fe7efc6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eosjs", - "version": "20.0.0-beta2.1", + "version": "20.0.0-beta2", "description": "Talk to eos API", "main": "dist/index.js", "scripts": { From 9acff87942be0935c19d5dd13729f04d638769f7 Mon Sep 17 00:00:00 2001 From: Mike Creque Date: Wed, 28 Nov 2018 13:56:41 -0500 Subject: [PATCH 28/37] publishes tip of develop branch to npm with edge tag and short commit hash --- .travis.yml | 8 ++++++++ scripts/publish.sh | 16 +++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec90df6a6..a2c488fb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,16 @@ language: node_js node_js: - '10.0.0' before_install: + - npm i -g npm@6.4.1 - yarn global add typescript - yarn global add webpack script: - yarn run lint - yarn run test +deploy: + - provider: script + skip_cleanup: true + script: + - ./scripts/publish.sh + on: + branch: develop \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh index e18b6390b..3af833b02 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -23,17 +23,14 @@ make_version() { git checkout -- . # Echo the status to the log so that we can see it is OK - git status - + git status + # Run the deploy build and increment the package versions - npm version -no-git-tag-version prerelease -} + current_commit="$(git rev-parse --short HEAD)"; -upload_files() { - git commit -a -m "Updating version [skip ci]" + npm version prerelease -preid "${current_commit}" -no-git-tag-version - # This make sure the current work area is pushed to the tip of the current branch - git push origin HEAD:${TRAVIS_BRANCH} + git commit -a -m "Updating version [skip ci]" } echo "Running on branch ${TRAVIS_BRANCH}": @@ -45,9 +42,6 @@ echo "Creating new version" make_version -echo "Pushing to git" -upload_files - echo "Publish to NPM" cp .npmrc.template $HOME/.npmrc From 5fe96f60fa8433e5b333a904890123840751c37e Mon Sep 17 00:00:00 2001 From: Cody Douglass Date: Thu, 29 Nov 2018 16:31:44 -0500 Subject: [PATCH 29/37] README reorganization first draft --- README.md | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5eacece04..9060953d4 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,17 @@ Documentation can be found [here](https://eosio.github.io/eosjs) ## Installation -### NodeJS +### NodeJS Dependency -`npm install eosjs@beta` +`npm install eosjs@beta` or `yarn add eosjs@beta` -## Basic Usage +### Browser Distribution + +Clone this repository locally then run `npm run build-web` or `yarn build-web`. The browser distribution will be located in `dist` and can be directly copied into your project repository. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). -### Browser +## Import + +### ES Modules Importing using ES6 module syntax in the browser is supported if you have a transpiler, such as Babel. ```js @@ -26,20 +30,22 @@ import { Api, JsonRpc, RpcError } from 'eosjs'; import JsSignatureProvider from 'eosjs/dist/eosjs-jssig' ``` -### NodeJS +### CommonJS -Importing using commonJS syntax is supported by node out of the box. +Importing using commonJS syntax is supported by NodeJS out of the box. ```js const { Api, JsonRpc, RpcError } = require('eosjs'); const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); const fetch = require('node-fetch'); // node only; not needed in browsers +const { TextEncoder, TextDecoder } = require('util') // node only; native TextEncoder/Decoder const { TextDecoder, TextEncoder } = require('text-encoding'); // IE11 and IE Edge Browsers only -const {TextEncoder,TextDecoder} = require('util') // node only; native TextEncoder/Decoder ``` +## Basic Usage + ### SignatureProvider -SignatureProvider holds private keys and is responsible for signing transactions. +The SignatureProvider holds private keys and is responsible for signing transactions. ***Using the default JsSignatureProvider in the browser is not secure and should only be used for development purposes. Use a secure vault outside of the context of the webpage to ensure security when signing transactions in production*** @@ -55,7 +61,7 @@ Open a connection to JSON-RPC, include `fetch` when on NodeJS. const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch }); ``` -### API Constructor +### API Include textDecoder and textEncoder when using in browser. ```js @@ -64,6 +70,8 @@ const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), te ### Sending a transaction +`transact()` is used to sign and push transactions onto the blockchain with an optional configuration object parameter. This parameter can override the default value of `broadcast: true`, and can be used to fill TAPOS fields given `blocksBehind` and `expireSeconds`. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (`expiration`, `ref_block_num`, `ref_block_prefix`) and will automatically be broadcast onto the chain. + ```js (async () => { const result = await api.transact({ @@ -105,15 +113,6 @@ try { ... ``` -## Browsers - -After running `npm run build-web` or `yarn build-web`, the browser distribution will be located in `dist`. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). - -## How it works - -`transact()` is used to sign and push transactions onto the blockchain with an optional configuration object parameter. This parameter can override the default value of `broadcast: true`, and can be used to fill TAPOS fields given `blocksBehind` and `expireSeconds`. Given no configuration options, transactions are expected to be unpacked with TAPOS fields (`expiration`, `ref_block_num`, `ref_block_prefix`) and will automatically be broadcast onto the chain. - - ## Running Tests ### Automated Test Suite From 068b7099f99dd4cf6a51521d6971356e57178323 Mon Sep 17 00:00:00 2001 From: Cody Douglass Date: Fri, 30 Nov 2018 11:39:21 -0500 Subject: [PATCH 30/37] add back integration tests and update readme --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9060953d4..1abc0f0ae 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Importing using ES6 module syntax in the browser is supported if you have a tran import { Api, JsonRpc, RpcError } from 'eosjs'; // If using default signature provider -import JsSignatureProvider from 'eosjs/dist/eosjs-jssig' +import JsSignatureProvider from 'eosjs/dist/eosjs-jssig'; ``` ### CommonJS @@ -37,8 +37,8 @@ Importing using commonJS syntax is supported by NodeJS out of the box. const { Api, JsonRpc, RpcError } = require('eosjs'); const JsSignatureProvider = require('eosjs/dist/eosjs-jssig'); const fetch = require('node-fetch'); // node only; not needed in browsers -const { TextEncoder, TextDecoder } = require('util') // node only; native TextEncoder/Decoder -const { TextDecoder, TextEncoder } = require('text-encoding'); // IE11 and IE Edge Browsers only +const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder +const { TextEncoder, TextDecoder } = require('text-encoding'); // React Native, IE11, and Edge Browsers only ``` ## Basic Usage @@ -117,3 +117,6 @@ try { ### Automated Test Suite `npm run test` or `yarn test` + +### Integration Test Suite +Run `npm run build-web` to build the browser distrubution then open `test.html` in the browser of your choice. The file should run through 5 tests, relaying the results onto the webpage with a 2 second delay after each test. The final test should throw an exception as it is missing the TAPOS fields and the config parameter. From 9ab7cf88759c5e71fc953558135eb372cf14575d Mon Sep 17 00:00:00 2001 From: Cody Douglass Date: Mon, 3 Dec 2018 17:33:30 -0500 Subject: [PATCH 31/37] adding back web integration tests --- README.md | 10 +-- src/rpc-web.ts | 4 ++ src/tests/web.html | 151 +++++++++++++++++++++++++++++++++++++++++++++ webpack.config.js | 3 +- 4 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 src/rpc-web.ts create mode 100644 src/tests/web.html diff --git a/README.md b/README.md index 1abc0f0ae..b438bdff2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Documentation can be found [here](https://eosio.github.io/eosjs) ### Browser Distribution -Clone this repository locally then run `npm run build-web` or `yarn build-web`. The browser distribution will be located in `dist` and can be directly copied into your project repository. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). +Clone this repository locally then run `npm run build-web` or `yarn build-web`. The browser distribution will be located in `dist-web` and can be directly copied into your project repository. For full browser usage examples, [see the documentation](https://eosio.github.io/eosjs/static/3.-Browsers.html). ## Import @@ -58,7 +58,7 @@ const signatureProvider = new JsSignatureProvider([defaultPrivateKey]); Open a connection to JSON-RPC, include `fetch` when on NodeJS. ```js -const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch }); +const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch }); ``` ### API @@ -115,8 +115,8 @@ try { ## Running Tests -### Automated Test Suite +### Automated Unit Test Suite `npm run test` or `yarn test` -### Integration Test Suite -Run `npm run build-web` to build the browser distrubution then open `test.html` in the browser of your choice. The file should run through 5 tests, relaying the results onto the webpage with a 2 second delay after each test. The final test should throw an exception as it is missing the TAPOS fields and the config parameter. +### Web Integration Test Suite +Run `npm run build-web` to build the browser distrubution then open `src/tests/web.html` in the browser of your choice. The file should run through 6 tests, relaying the results onto the webpage with a 2 second delay after each test. The final 2 tests should relay the exceptions being thrown onto the webpage for an invalid transaction and invalid rpc call. diff --git a/src/rpc-web.ts b/src/rpc-web.ts new file mode 100644 index 000000000..63122257b --- /dev/null +++ b/src/rpc-web.ts @@ -0,0 +1,4 @@ +import JsonRpc from "./eosjs-jsonrpc"; +import RpcError from "./eosjs-rpcerror"; + +export { JsonRpc as default, RpcError }; diff --git a/src/tests/web.html b/src/tests/web.html new file mode 100644 index 000000000..95dde106c --- /dev/null +++ b/src/tests/web.html @@ -0,0 +1,151 @@ +

+
+
+
+
+
diff --git a/webpack.config.js b/webpack.config.js
index ba682afb8..e597f02f1 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -3,8 +3,7 @@ const path = require('path');
 module.exports = {
     entry: {
         eosjs_api: './src/eosjs-api.ts',
-        eosjs_jsonrpc: './src/eosjs-jsonrpc.ts',
-        eosjs_rpcerror: './src/eosjs-rpcerror.ts',
+        eosjs_jsonrpc: './src/rpc-web.ts',
         eosjs_jssig: './src/eosjs-jssig.ts',
     },
     devtool: 'inline-source-map',

From 1576e6c31e82a46069c301c604c0c60b1c95d560 Mon Sep 17 00:00:00 2001
From: Mike Creque 
Date: Mon, 3 Dec 2018 12:03:00 -0500
Subject: [PATCH 32/37] publish latest and beta releases on tag from master

---
 .travis.yml              | 16 +++++++++++--
 scripts/is_latest.sh     |  2 +-
 scripts/publish-edge.sh  | 26 +++++++++++++++++++++
 scripts/publish-tag.sh   | 37 ++++++++++++++++++++++++++++++
 scripts/publish-utils.sh | 16 +++++++++++++
 scripts/publish.sh       | 49 ----------------------------------------
 6 files changed, 94 insertions(+), 52 deletions(-)
 create mode 100755 scripts/publish-edge.sh
 create mode 100755 scripts/publish-tag.sh
 create mode 100755 scripts/publish-utils.sh
 delete mode 100755 scripts/publish.sh

diff --git a/.travis.yml b/.travis.yml
index a2c488fb0..cfb6636e7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,6 @@
+env:
+  global:
+    PUBLISH_NPM_LATEST_FROM="master"
 sudo: false
 language: node_js
 node_js:
@@ -6,6 +9,8 @@ before_install:
   - npm i -g npm@6.4.1
   - yarn global add typescript
   - yarn global add webpack 
+before_script:
+  - source ./scripts/is_latest.sh
 script:
   - yarn run lint
   - yarn run test
@@ -13,6 +18,13 @@ deploy:
   - provider: script
     skip_cleanup: true
     script: 
-      - ./scripts/publish.sh
+      - ./scripts/publish-edge.sh
     on: 
-      branch: develop
\ No newline at end of file
+      branch: develop
+  - provider: script
+    skip_cleanup: true
+    script: 
+      - ./scripts/publish-tag.sh $PUBLISH_NPM_LATEST_FROM
+    on: 
+      tags: true
+      condition: $TRAVIS_IS_LATEST_TAG = true # sourced from ./scripts/is_latest.sh
\ No newline at end of file
diff --git a/scripts/is_latest.sh b/scripts/is_latest.sh
index 539542747..87224a102 100755
--- a/scripts/is_latest.sh
+++ b/scripts/is_latest.sh
@@ -11,7 +11,7 @@ if [ "$latest_tag" == "" ]; then
     latest_tag="v0.0.0";
 else
     tag_commit="$(git rev-list -n 1 ${latest_tag})";
-    if [ "$tag_commit" = "$current_commit" ]; then
+    if [ "$tag_commit" == "$current_commit" ]; then
         is_latest=true;
     fi
 fi
diff --git a/scripts/publish-edge.sh b/scripts/publish-edge.sh
new file mode 100755
index 000000000..552dbff28
--- /dev/null
+++ b/scripts/publish-edge.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+. "${TRAVIS_BUILD_DIR}/scripts/publish-utils.sh";
+
+echo "Running on branch/tag ${TRAVIS_BRANCH}":
+
+echo "Setting up git"
+setup_git
+
+echo "Creating new version"
+git checkout -- .
+
+git status 
+
+# get the short commit hash to include in the npm package
+current_commit="$(git rev-parse --short HEAD)";
+
+npm version prerelease -preid "${current_commit}" -no-git-tag-version
+
+git commit -a -m "Updating version [skip ci]"
+
+echo "Publish to NPM"
+
+cp .npmrc.template $HOME/.npmrc 
+
+npm publish --tag edge
\ No newline at end of file
diff --git a/scripts/publish-tag.sh b/scripts/publish-tag.sh
new file mode 100755
index 000000000..4e333fc5b
--- /dev/null
+++ b/scripts/publish-tag.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+. "${TRAVIS_BUILD_DIR}/scripts/publish-utils.sh";
+
+if [[ "$TRAVIS_TAG" == "" ]]; then
+  echo "No tag specified, skipping...";
+else
+  echo "Running on branch/tag ${TRAVIS_TAG}":
+
+  echo "Setting up git"
+  setup_git
+
+  echo "Creating new version"
+  git checkout -- .
+
+  git status
+
+  npm version -no-git-tag-version $TRAVIS_TAG
+
+  echo "Pushing to git"
+  git commit -a -m "Publishing version ${TRAVIS_TAG} [skip ci]"
+
+  git push origin HEAD:${1}
+
+  echo "Build and Publish to NPM"
+
+  cp .npmrc.template $HOME/.npmrc 
+
+  if [[ "$TRAVIS_TAG" == *"-beta"* ]]; then
+    echo "Publishing with beta tag to npm"
+    npm publish --tag beta
+  else
+    echo "Publishing with latest tag to npm"
+    npm publish
+  fi
+fi
+
diff --git a/scripts/publish-utils.sh b/scripts/publish-utils.sh
new file mode 100755
index 000000000..33ad021e2
--- /dev/null
+++ b/scripts/publish-utils.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+setup_git() {
+  # Set the user name and email to match the API token holder
+  # This will make sure the git commits will have the correct photo
+  # and the user gets the credit for a checkin
+  git config --global user.email "devops@block.one"
+  git config --global user.name "blockone-devops"
+  git config --global push.default matching
+  
+  # Get the credentials from a file
+  git config credential.helper "store --file=.git/credentials"
+  
+  # This associates the API Key with the account
+  echo "https://${GITHUB_API_KEY}:@github.com" > .git/credentials
+}
\ No newline at end of file
diff --git a/scripts/publish.sh b/scripts/publish.sh
deleted file mode 100755
index 3af833b02..000000000
--- a/scripts/publish.sh
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/bash
-
-setup_git() {
-  # Set the user name and email to match the API token holder
-  # This will make sure the git commits will have the correct photo
-  # and the user gets the credit for a checkin
-  git config --global user.email "devops@block.one"
-  git config --global user.name "blockone-devops"
-  git config --global push.default matching
-  
-  # Get the credentials from a file
-  git config credential.helper "store --file=.git/credentials"
-  
-  # This associates the API Key with the account
-  echo "https://${GITHUB_API_KEY}:@github.com" > .git/credentials
-}
-
-make_version() {
-  # Make sure that the workspace is clean
-  # It could be "dirty" if
-  # 1. package-lock.json is not aligned with package.json
-  # 2. npm install is run
-  git checkout -- .
-  
-  # Echo the status to the log so that we can see it is OK
-  git status 
-
-  # Run the deploy build and increment the package versions
-  current_commit="$(git rev-parse --short HEAD)";
-
-  npm version prerelease -preid "${current_commit}" -no-git-tag-version
-
-  git commit -a -m "Updating version [skip ci]"
-}
-
-echo "Running on branch ${TRAVIS_BRANCH}":
-
-echo "Setting up git"
-setup_git
-
-echo "Creating new version"
-
-make_version
-
-echo "Publish to NPM"
-
-cp .npmrc.template $HOME/.npmrc 
-
-npm publish --tag edge
\ No newline at end of file

From 1f6d951f5235d545f4d9181403e81e86a319d7bd Mon Sep 17 00:00:00 2001
From: Cody Douglass 
Date: Tue, 4 Dec 2018 10:50:43 -0500
Subject: [PATCH 33/37] making debug and production files for web build process

---
 package.json                          |    2 +-
 src/tests/web.html                    |    6 +-
 webpack.config.js => webpack.debug.js |    4 -
 webpack.prod.js                       |   31 +
 yarn.lock                             | 2207 ++++++++-----------------
 5 files changed, 735 insertions(+), 1515 deletions(-)
 rename webpack.config.js => webpack.debug.js (92%)
 create mode 100644 webpack.prod.js

diff --git a/package.json b/package.json
index c2ae55dd8..866c15836 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
     "lint": "tslint -c tslint.json src/**/*.ts",
     "lint-fix": "tslint -c tslint.json src/**/*.ts --fix",
     "build": "tsc -p ./tsconfig.json && cp src/ripemd.es5.js dist/ripemd.js",
-    "build-web": "webpack",
+    "build-web": "webpack --config webpack.prod.js && webpack --config webpack.debug.js",
     "clean": "rm -rf dist",
     "docs-init": "sh .docs/scripts/init.sh",
     "docs-build": "sh .docs/scripts/build.sh",
diff --git a/src/tests/web.html b/src/tests/web.html
index 95dde106c..1abca2516 100644
--- a/src/tests/web.html
+++ b/src/tests/web.html
@@ -1,8 +1,8 @@
 

 
-
-
-
+
+
+
 
-
-
+
+
+
 
-
-
-
+
+
+
 
 ```
 
+## Debugging
+
+If you would like readable source files for debugging, change the file reference to the `-debug.js` files inside `dist-web/debug`.  These files should only be used for development as they are over 10 times as large as the minified versions, and importing the debug versions will increase loading times for the end user.
+
 ## IE11 and Edge Support
 If you need to support IE11 or Edge you will also need to install a text-encoding polyfill as eosjs Signing is dependent on the TextEncoder which IE11 and Edge do not provide.  Pass the TextEncoder and TextDecoder to the API constructor as demonstrated in the [ES 2015 example](#node-es-2015).  Refer to the documentation here https://github.com/inexorabletash/text-encoding to determine the best way to include it in your project.
diff --git a/docs/4.-Reading blockchain-Examples.md b/docs/4.-Reading blockchain-Examples.md
index fd957a51f..4460e6481 100644
--- a/docs/4.-Reading blockchain-Examples.md	
+++ b/docs/4.-Reading blockchain-Examples.md	
@@ -3,9 +3,9 @@
 Reading blockchain state only requires an instance of `JsonRpc` connected to a node.
 
 ```javascript
-const {JsonRpc } = require('eosjs');
+const { JsonRpc } = require('eosjs');
 const fetch = require('node-fetch');           // node only; not needed in browsers
-const rpc = new JsonRpc('http://127.0.0.1:8000', { fetch });
+const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch });
 ```
 
 ## Examples
diff --git a/src/tests/web.html b/src/tests/web.html
index 7fea306bd..95dde106c 100644
--- a/src/tests/web.html
+++ b/src/tests/web.html
@@ -5,7 +5,7 @@