Skip to content

Commit

Permalink
Moved all flatworm docs to inline code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 19, 2020
1 parent 9712592 commit 2aeb4e9
Show file tree
Hide file tree
Showing 18 changed files with 979 additions and 80 deletions.
38 changes: 37 additions & 1 deletion docs.wrm/api/contract/example.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,43 @@ _section: Example: ERC-20 Contract

_subsection: Connecting to a Contract

_code: token.txt
_code: A simple ERC-20 contract @lang<javascript>

// A Human-Readable ABI; any supported ABI format could be used
const abi = [
// Read-Only Functions
"function balanceOf(address owner) view returns (uint256)",
"function decimals() view returns (uint8)",
"function symbol() view returns (string)",

// Authenticated Functions
"function transfer(address to, uint amount) returns (boolean)",

// Events
"event Transfer(address indexed from, address indexed to, uint amount)"
];

// This can be an address or an ENS name
const address = "dai.tokens.ethers.eth";

// An example Provider
const provider = ethers.getDefaultProvider();

// An example Signer
const signer = ethers.Wallet.createRandom().connect(provider);

// Read-Only; By connecting to a Provider, allows:
// - Any constant function
// - Querying Filters
// - Populating Unsigned Transactions for non-constant methods
// - Estimating Gas for non-constant (as an anonymous sender)
// - Static Calling non-constant methods (as anonymous sender)
const erc20 = new ethers.Contract(address, abi, provider);

// Read-Write; By connecting to a Signer, allows:
// - Everything from Read-Only (except as Signer, not anonymous)
// - Sending transactions for non-constant functions
const erc20_rw = new ethers.Contract(address, abi, signer)


_heading: ERC20Contract @INHERIT<[[contract]]>
Expand Down
37 changes: 35 additions & 2 deletions docs.wrm/api/providers/provider.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,27 @@ sent to the network.

_heading: Examples

_code: example-account.js
_code: @lang<javascript>

// <hide>
const provider = ethers.getDefaultProvider()
// </hide>

// Get the balance for an account...
provider.getBalance("ricmoo.firefly.eth");
//!

// Get the code for a contract...
provider.getCode("registrar.firefly.eth");
//!

// Get the storage value at position 0...
provider.getStorageAt("registrar.firefly.eth", 0)
//!

// Get transaction count of an account...
provider.getTransactionCount("ricmoo.firefly.eth");
//!


_subsection: Blocks Methods
Expand Down Expand Up @@ -52,7 +72,20 @@ not have an address configured, ``null`` is returned.

_heading: Examples

_code: example-ens.js
_code: @lang<javascript>

// <hide>
const provider = ethers.getDefaultProvider()
// </hide>

// Reverse lookup of an ENS by address...
provider.lookupAddress("0x6fC21092DA55B392b045eD78F4732bff3C580e2c");
//!

// Lookup an address of an ENS name...
provider.resolveName("ricmoo.firefly.eth");
//!


_subsection: Logs Methods

Expand Down
2 changes: 1 addition & 1 deletion docs.wrm/api/providers/types.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ If this transaction has a ``null`` to address, it is an **init transaction**
used to deploy a contract, in which case this is the address created by that
contract.

To compute a contract address, the [getContractAddress](utils-getcontractaddress)
To compute a contract address, the [getContractAddress](utils-getContractAddress)
utility function can also be used with a [[provider-transactionresponse]]
object, which requires the transaction nonce and the address of the sender.

Expand Down
27 changes: 22 additions & 5 deletions docs.wrm/api/utils/address.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ accepts an address can receive an ICAP address, and it will be converted interna
To convert an address into the ICAP format, see [getIcapAddress](utils-getIcapAddress).


_subsection: Functions
_subsection: Converting and Verifying @<urils--address-basic>

_property: ethers.utils.getAddress(address) => string<[[address]]> @<utils-getAddress> @SRC<address>
Returns //address// as a Checksum Address.
Expand All @@ -49,18 +49,35 @@ the checksum is invalid, an InvalidArgument Error is throw.

The value of //address// may be any supported address format.

_property: ethers.utils.getIcapAddress(address) => string<[IcapAddress](address-icap)> @<utils-getIcapAddress> @SRC<address>
Returns //address// as an [ICAP address](link-icap).
Supports the same restrictions as [utils.getAddress](utils-getAddress).

_property: ethers.utils.isAddress(address) => boolean @<utils-isAddress> @SRC<address>
Returns true if //address// is valid (in any supported format).

_property: ethers.utils.getIcapAddress(address) => string<[IcapAddress](address-icap)> @<utils-getIcapAddress> @SRC<address>
Returns //address// as an [ICAP address](link-icap).
Supports the same restrictions as [utils.getAddress](utils-getAddress).

_property: ethers.utils.getContractAddress(transaction) => string<[[address]]> @<utils-getcontractaddress> @SRC<address>
_subsection: Derivation @<utils--address-computation>

_property: ethers.utils.computeAddress(publicOrPrivateKey) => string<[[address]]> @<utils-computeAddress> @SRC<transactions>
Returns the address for //publicOrPrivateKey//. A public key may be
compressed or uncompressed, and a private key will be converted
automatically to a public key for the derivation.

_property: ethers.utils.recoverAddress(digest, signature) => string<[[address]]> @<utils-recoverAddress> @SRC<transactions>
Use [[link-wiki-ecrecover]] to determine the address that signed //digest// to
which generated //signature//.


_subsection: Contracts Addresses @<utils--contract-addresses>

_property: ethers.utils.getContractAddress(transaction) => string<[[address]]> @<utils-getContractAddress> @SRC<address>
Returns the contract address that would result if //transaction// was
used to deploy a contract.

_property: ethers.utils.getCreate2Address(from, salt, initCodeHash) => string<[[address]]> @<utils-getCreate2Address> @SRC<address>
Returns the contract address that would result from the given
[CREATE2](link-eip-1014) call.



76 changes: 71 additions & 5 deletions docs.wrm/api/utils/bignumber.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@ and parameters which accept values will generally accept them.

_heading: Importing

_code: bignumber-import.source
_code: CommonJS @lang<script>

// From the Umbrella ethers package...
const { BigNumber } = require("ethers");

// From the bignumber pacakge...
const { BigNumber } = require("@ethersproject/bignumber");


_code: ES6 and TypeScript CommonJS @lang<script>

// From the Umbrella ethers package...
import { BigNumber } from "ethers";

// From the bignumber pacakge...
import { BigNumber } from "@ethersproject/bignumber";


_subsection: Types

Expand Down Expand Up @@ -50,7 +66,46 @@ Returns an instance of a **BigNumber** for //aBigNumberish//.

_heading: Examples: @<>

_code: bignumber-create.js
_code: @lang<javascript>

// From a decimal string...
BigNumber.from("42")
//!

// From a hexstring...
BigNumber.from("0x2a")
//!

// From a negative hexstring...
BigNumber.from("-0x2a")
//!

// From an Array (or Uint8Array)...
BigNumber.from([ 42 ])
//!

// From an existing BigNumber...
let one1 = constants.One;
let one2 = BigNumber.from(one1)

one2
//!

// ...which returns the same instance
one1 === one2
//!

// From a (safe) number...
BigNumber.from(42)
//!

// From a ES2015 BigInt... (only on platforms with BigInt support)
BigNumber.from(42n)
//!

// Numbers outside the safe range fail:
BigNumber.from(Number.MAX_SAFE_INTEGER);
//! error


_subsection: Methods
Expand All @@ -65,7 +120,7 @@ _property: bignumber.add(otherValue) => [[bignumber]] @SRC<bignumber>
Returns a BigNumber with the value of //bignumber// **+** //otherValue//.

_property: bignumber.sub(otherValue) => [[bignumber]] @SRC<bignumber>
Returns a BigNumber with the value of //bignumber// **&ndash;** //otherValue//.
Returns a BigNumber with the value of //bignumber// **-** //otherValue//.

_property: bignumber.mul(otherValue) => [[bignumber]] @SRC<bignumber>
Returns a BigNumber with the value of //bignumber// **&times;** //otherValue//.
Expand Down Expand Up @@ -146,7 +201,13 @@ Returns true if and only if the //object// is a BigNumber object.

_heading: Examples

_code: bignumber-examples.js
_code: @lang<javascript>

let a = BigNumber.from(42);
let b = BigNumber.from("91");

a.mul(b);
//!


_subsection: Notes
Expand All @@ -171,7 +232,12 @@ experience rounding errors.

To demonstrate how this may be an issue in your code, consider:

_code: bignumber-ieee754.js
_code: @lang<javascript>

(Number.MAX_SAFE_INTEGER + 2 - 2) == (Number.MAX_SAFE_INTEGER)
//!

_null:

To remedy this, all numbers (which can be large) are stored
and manipulated as [Big Numbers](bignumber).
Expand Down
39 changes: 38 additions & 1 deletion docs.wrm/api/utils/bytes.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,31 @@ zeros.

_heading: Examples

_code: bytes-conversion.js
_code: @lang<javascript>

// Convert a hexstring to a Uint8Array
arrayify("0x1234")
//!

// Convert an Array to a hexstring
hexlify([1, 2, 3, 4])
//!

// Convert an Object to a hexstring
hexlify({ length: 2, "0": 1, "1": 2 })
//!

// Convert an Array to a hexstring
hexlify([ 1 ])
//!

// Convert a number to a stripped hex value
hexValue(1)
//!

// Convert an Array to a stripped hex value
hexValue([ 1, 2 ])
//!


_subsection: Array Manipulation
Expand Down Expand Up @@ -139,3 +163,16 @@ Return a new Uint8Array of //length// random bytes.

_property: ethers.utils.shuffled(array) => Array<any> @<utils.shuffled> @SRC<random>
Return a copy of //array// shuffled using [[link-wiki-shuffle]].

_code: Examples @lang<javascript>

utils.randomBytes(8)
//!

const foo = [ 1, 2, 3, 4, 5, 6, 7 ];
utils.shuffled(foo);
//!

// The original array is unscathed...
foo
//!
5 changes: 4 additions & 1 deletion docs.wrm/api/utils/constants.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ The **ethers.contants** Object contains commonly used values.

_heading: Importing

_code: constants-import.js
_code: @lang<script>

const { constants } = require("ethers");
const { constants } = require("@ethersproject/constants");


_subsection: Bytes
Expand Down
32 changes: 19 additions & 13 deletions docs.wrm/api/utils/display-logic.wrm
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ _subsection: Units

_heading: Decimal Count

The //unit// specified may be an integer, which indicates how
many decimal place the unit has. For example, 1 ether has 18 decimal
places for wei, and if this library were used with Bitcoin, 1 BTC
has 8 decimal places for satoshis.
A **Unit** can be specified as an number, which indicates the
number of decimal places that should be used.

**Examples:**

- 1 ether in wei, has **18** decimal places (i.e. 1 ether represents 10^^18^^ wei)
- 1 bitcoin in Satoshi, has **8** decimal places (i.e. 1 bitcoin represents 10^^8^^ satoshi)

_heading: Named Units

In addition to specifying //unit// as a number of decimals, there
are several common units, which can be passed in as a string:
There are also several common **Named Units**, in which case their name (as
a string) may be used.

_table: @STYLE<compact>

- **wei** --- 0
- **kwei** --- 3
- **mwei** --- 6
- **gwei** --- 9
- **szabo** --- 12
- **finney** --- 15
- **ether** --- 18
| **Name** | **Decimals** |
| //wei// | 0 |
| //kwei// | 3 |
| //mwei// | 6 |
| //gwei// | 9 |
| //szabo// | 12 |
| //finney// | 15 |
| //ether// | 18 |


_subsection: Functions
Expand Down
Loading

0 comments on commit 2aeb4e9

Please sign in to comment.