Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Browser Documentation and Fixes #1247

Merged
merged 6 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js.map

Large diffs are not rendered by default.

182 changes: 148 additions & 34 deletions docs/index.html

Large diffs are not rendered by default.

581 changes: 340 additions & 241 deletions docs/typedoc/api.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/typedoc/assets/js/search.json

Large diffs are not rendered by default.

290 changes: 192 additions & 98 deletions docs/typedoc/classes/_api_.ethereumapi.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/typedoc/modules/_api_.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h3>Typed<wbr>Data</h3>
<div class="tsd-signature tsd-kind-icon">Typed<wbr>Data<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Exclude</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">Parameters&lt;typeof signTypedData_v4&gt;[1][&quot;data&quot;]</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-type">NotTypedData</span><span class="tsd-signature-symbol">&gt;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/f5f51b3/src/chains/ethereum/ethereum/src/api.ts#L104">chains/ethereum/ethereum/src/api.ts:104</a></li>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/92d1fb744/src/chains/ethereum/ethereum/src/api.ts#L104">chains/ethereum/ethereum/src/api.ts:104</a></li>
</ul>
</aside>
</section>
Expand All @@ -120,7 +120,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> CLIENT_<wbr>VERSION</h3>
<div class="tsd-signature tsd-kind-icon">CLIENT_<wbr>VERSION<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> = &#x60;Ganache/v${version}/EthereumJS TestRPC/v${version}/ethereum-js&#x60;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/f5f51b3/src/chains/ethereum/ethereum/src/api.ts#L91">chains/ethereum/ethereum/src/api.ts:91</a></li>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/92d1fb744/src/chains/ethereum/ethereum/src/api.ts#L91">chains/ethereum/ethereum/src/api.ts:91</a></li>
</ul>
</aside>
</section>
Expand All @@ -130,7 +130,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> PROTOCOL_<wbr>VERSION</h3>
<div class="tsd-signature tsd-kind-icon">PROTOCOL_<wbr>VERSION<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Data</span><span class="tsd-signature-symbol"> = Data.from(&quot;0x3f&quot;)</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/f5f51b3/src/chains/ethereum/ethereum/src/api.ts#L92">chains/ethereum/ethereum/src/api.ts:92</a></li>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/92d1fb744/src/chains/ethereum/ethereum/src/api.ts#L92">chains/ethereum/ethereum/src/api.ts:92</a></li>
</ul>
</aside>
</section>
Expand All @@ -140,7 +140,7 @@ <h3><span class="tsd-flag ts-flagConst">Const</span> RPC_<wbr>MODULES</h3>
<div class="tsd-signature tsd-kind-icon">RPC_<wbr>MODULES<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">object</span><span class="tsd-signature-symbol"> = {eth: &quot;1.0&quot;,net: &quot;1.0&quot;,rpc: &quot;1.0&quot;,web3: &quot;1.0&quot;,evm: &quot;1.0&quot;,personal: &quot;1.0&quot;} as const</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/f5f51b3/src/chains/ethereum/ethereum/src/api.ts#L93">chains/ethereum/ethereum/src/api.ts:93</a></li>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/92d1fb744/src/chains/ethereum/ethereum/src/api.ts#L93">chains/ethereum/ethereum/src/api.ts:93</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -173,7 +173,7 @@ <h3>version</h3>
<div class="tsd-signature tsd-kind-icon">version<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/f5f51b3/src/chains/ethereum/ethereum/src/api.ts#L87">chains/ethereum/ethereum/src/api.ts:87</a></li>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/92d1fb744/src/chains/ethereum/ethereum/src/api.ts#L87">chains/ethereum/ethereum/src/api.ts:87</a></li>
</ul>
</aside>
</section>
Expand All @@ -190,7 +190,7 @@ <h3>assert<wbr>Exceptional<wbr>Transactions</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/f5f51b3/src/chains/ethereum/ethereum/src/api.ts#L111">chains/ethereum/ethereum/src/api.ts:111</a></li>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/92d1fb744/src/chains/ethereum/ethereum/src/api.ts#L111">chains/ethereum/ethereum/src/api.ts:111</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -213,7 +213,7 @@ <h3>autofill<wbr>Default<wbr>Transaction<wbr>Values</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/f5f51b3/src/chains/ethereum/ethereum/src/api.ts#L55">chains/ethereum/ethereum/src/api.ts:55</a></li>
<li>Defined in <a href="https://github.com/trufflesuite/ganache/blob/92d1fb744/src/chains/ethereum/ethereum/src/api.ts#L55">chains/ethereum/ethereum/src/api.ts:55</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
31 changes: 30 additions & 1 deletion src/chains/ethereum/utils/src/errors/coded-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,42 @@ export class CodedError extends Error {
code: number;
constructor(message: string, code: number) {
super(message);
Error.captureStackTrace(this, this.constructor);
CodedError.captureStackTraceExtended.bind(this, message);

this.code = code;
}

static from(error: Error, code: JsonRpcErrorCode) {
const codedError = new CodedError(error.message, code);
codedError.stack = error.stack;
return codedError;
}
static nonEnumerableProperty(value) {
// The field `enumerable` is `false` by default.
return {
value: value,
writable: true,
configurable: true
};
}
static captureStackTraceExtended(message: string) {
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
} else {
// Generic way to set the error stack trace.
Object.defineProperty(
this,
"stack",
CodedError.nonEnumerableProperty(Error(message).stack)
);

// Use the `+` operator with an empty string to implicitly type cast the
// `message` argument into a string.
Object.defineProperty(
this,
"message",
CodedError.nonEnumerableProperty(message !== void 0 ? "" + message : "")
);
}
}
}
2 changes: 1 addition & 1 deletion src/chains/ethereum/utils/src/errors/runtime-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class RuntimeError extends CodedError {

super(message, JsonRpcErrorCode.INVALID_INPUT);

Error.captureStackTrace(this, this.constructor);
CodedError.captureStackTraceExtended.bind(this, message);
this.name = this.constructor.name;

const returnValue = execResult.returnValue;
Expand Down
19 changes: 18 additions & 1 deletion src/packages/ganache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Ganache is an Ethereum simulator that makes developing Ethereum applications fas

## Getting Started

Ganache can be used from the [command line](#command-line-use) or [programmatically](#programmatic-use) via Node.js.
Ganache can be used from the [command line](#command-line-use), [programmatically](#programmatic-use) via Node.js, or [in the browser](#browser-use).

### Command line use

Expand Down Expand Up @@ -192,6 +192,23 @@ const ganache = require("ganache");
const provider = new ethers.providers.Web3Provider(ganache.provider());
```

### Browser Use

You can also use Ganache in the browser by adding the following script to your HTML:

```html
<script src="https://cdn.jsdelivr.net/npm/ganache@version"></script>
MicaiahReid marked this conversation as resolved.
Show resolved Hide resolved
```

NOTE: the `version` in the above path needs to be replaced with a version number or tag that is listed in [npm](https://www.npmjs.com/package/ganache?activeTab=versions).
MicaiahReid marked this conversation as resolved.
Show resolved Hide resolved

From there, Ganache is available in your browser for use:

```Javascript
MicaiahReid marked this conversation as resolved.
Show resolved Hide resolved
const options = {};
const provider = Ganache.provider(options);
```

## Documentation

New RPC documentation coming soon! See https://github.com/trufflesuite/ganache/tree/master#options for Ganache v2 documentation.
Expand Down