docs: added some section stubs

This commit is contained in:
Richard Moore 2022-12-30 17:01:15 -05:00
parent 24406a5127
commit c8d761a1a3
2 changed files with 297 additions and 0 deletions

93
docs.wrm/contributing.wrm Normal file

@ -0,0 +1,93 @@
_section: Contributings and Hacking @<about-contrib> @priority<-90>
Pull requests are welcome, but please keep the following in mind:
- Backwards-compatibility-breaking changes will not be accepted;
they may be considered for the next major version
- Security is important; adding dependencies require fairly
convincing arguments as to why
- The library aims to be lean, so keep an eye on the
``dist/ethers.min.js`` file size before and after your
changes (the ``build-clean`` target includes these stats)
- Keep the PR simple, readable and confined to the relevant
files; see below for which files to change
- Add test cases for both expected and unexpected input
- Any new features need to be supported by me (future issues,
documentation, testing, migration), so anything that is
overly complicated or specific may not be accepted
- Everyone is working hard; **be kind and respectful**
It is always //highly recommended// that you open a [[link-discussion]]
**before** beginning a PR.
_subsection: Documentation @<about-contrib-docs>
The documentation is an area which can always benefit from extra
eyes, extra knowledge and extra examples.
Contributing to the documentation is welcome
When making changes to documentation, please ensure that all
changes are made **only** to:
- Updating ``/docs.wrm/*\*.wrm``
- Adding links: ``/docs.wrm/links/*.txt``
- Updating API jsdocs: ``/*\* ... */`` comment blocks within ``/src.ts/``
Generally changes to ``/docs.wrm/config.wrm`` should not be
made, and if you feel it is necessary, please consider opening
a [[link-discussion]] first.
Similarly, when adding a new sections, a [[link-discussion]] is
preferred.
All changes should be in the Flatworm Markdown Dialect.
_subsection: Fixing Bugs @<about-contrib-bugs>
In general the **only** files you should ever include in a PR are:
- TypeScript source: ``/src.ts/*\*.ts``
Do not include a ``package.json`` with the updated ``tarballHash``
or ``version``, and do not include any generated files in your PR.
A bug fix **must not** modify anything requiring a minor version
bump (see [[about-contrib-feature]]), such as changing a method
signature or altering the exports.
_subsection: Adding Features @<about-contrib-feature>
Contributing new features usually require a deeper understanding
of the internal interactions with Ethers and its components, and
generally requires a minor version bumpincludes anything w
When making any of the following changes, you must first open a
[[link-discussion]] as the minor version will need to be bumped.
- any signature change (such as adding a parameter, changing a
parameter type, changing the return type)
- adding any new export; such as a class, function or constants
- adding any method to any class
- changing any ``exports`` property within the ``package.json``
Changes of this sort should not be made without serious consideration
and discussion.
_subsection: Building @<building>
_code: @lang<shell>
/home/ricmoo> git clone @TODO
/home/ricmoo> cd ethers
/home/ricmoo/ethers> npm install
/home/ricmoo/ethers> npm run auto-build
_null:
_subsection: Previewing Documentation

@ -1,3 +1,207 @@
_section: Getting Started @<getting-started> @priority<100>
This
The v6 getting started is coming soon...
_heading: Installing
_code: Install via NPM @lang<shell>
# Create a new folder for your project
/home/ricmoo> mkdir test-ethers
/home/ricmoo> cd test-ethers
# Install ethers
/home/ricmoo/test-ethers> npm install ethers@beta-exports
_heading: Importing
Everything in Ethers is exported at the root as well as on the ``ethers``
object. There are also ``exports`` in the ``package.json`` to facilitate
sub-packages.
Generally this documentation will presume all exports from ethers
have been imported in the code examples, but you may import the
necessary objects any way you wish.
_code: Node.js @lang<script>
// Import everything
import { ethers } from "ethers";
// Import just a few select items
import { BrowserProvider, parseUnits } from "ethers";
// Import from a specific export
import { HDNodeWallet } from "ethers/wallet";
_code: Web Browsers (ESM) @lang<script>
<script type="module">
import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.2/ethers.min.js";
// Your code here...
</script>
_subsection: Some Common Terminology
_heading: PROVIDER
_heading: SIGNER
_heading: TRANSACTION
_heading: Receipt
_heading: CONTRACT
_subsection: Connecting to Ethereum
_heading: MetaMask (and other injected providers)
The quickest and easiest way to experiment and begin developing
on Ethereum is to use [[link-metamask]], which is a browser
extension that injects objects into the ``window``, providing:
- read-only access to the Ethereum network (a [[Provider]])
- authenticated write access backed by a private key (a [[Signer]])
When requesting access to the authenticated methods, such as
sending a transaction or even requesting the private key addess,
MetaMask will show a pop-up to the user asking for permission.
_code: @lang<script>
let signer = null;
let provider;
if (window.ethereum == null) {
// If MetaMask is not installed, we use the default provider,
// which is backed by a variety of third-party services (such
// as INFURA). They do not have private keys installed so are
// only have read-only access
console.log("MetaMask not installed; using read-only defaults")
provider = ethers.getDefaultProvider()
} else {
// Connect to the MetaMask EIP-1193 object. This is a standard
// protocol that allows Ethers access to make all read-only
// requests through MetaMask.
provider = new ethers.BrowserProvider(window.ethereum)
// It also provides an opportunity to request access to write
// operations, which will be performed by the private key
// that MetaMask manages for the user.
signer = await provider.getSigner();
}
_heading: Custom RPC Backend
If you are running your own Ethereum node (e.g. [[link-geth]])
or using a custom third-party service (e.g. [[link-infura]]),
you can use the [[JsonRpcProvider]] directly, which communicates
using the [[link-jsonrpc]] protocol.
When using your own Ethereum node or a developer-base blockchain,
such as Hardhat or Ganache, you can get access the accounts with
[[JsonRpcProvider-getSigner]].
_code: @lang<script>
// If no %%url%% is provided, it connects to the default
// http://localhost:8545, which most nodes use.
provider = new ethers.JsonRpcProvider(url)
// Get write access as an account by getting the signer
signer = await provider.getSigner()
_subsection: Interacting with the Blockchain
_heading: Querying State (reading)
Once you have a [[Provider]], you have a read-only connection to
the data on the blockchain. This can be used to query the current
account state, fetch historic logs, look up contract code and so on.
_code: @lang<javascript>
//_hide: provider = new InfuraProvider();
// Look up the current block number (i.e. height)
await provider.getBlockNumber()
//_result:
// Get the current balance of an account (by address or ENS name)
balance = await provider.getBalance("ethers.eth")
//_result:
// Since the balance is in wei, you may wish to display it
// in ether instead.
formatEther(balance)
//_result:
// Get the next nonce required to send a transaction
await provider.getTransactionCount("ethers.eth")
//_result:
_heading: Sending Transactions (writing)
To write to the blockchain you require access to a private key
which controls some account. In most cases, those private keys
are not accessible directly to your code, and instead you make
requests via a [[Signer]], which dispatches the request to a
service (such as [[link-metamask]]) which provides strictly
gated access and requires feedback to the user to approve or
reject operations.
_code: @lang<script>
// When sending a transaction, the value is in wei, so parseEther
// converts ether to wei.
tx = await signer.send({
to: "ethers.eth",
value: parseEther("1.0")
});
//_result:
// Often you may wish to wait until the transaction is mined
receipt = await tx.wait();
//_result:
_heading: User Interaction
explain ether vs gwei... format vs parse. getAddress, resolveAddress
_code: @lang<javascript>
// Convert user-provided strings in ether to wei for a value
eth = parseEther("1.0")
//_result:
// Convert user-provided strings in gwei to wei for max base fee
feePerGas = parseUnits("4.5", "gwei")
//_result:
// Convert a value in wei to a string in ether to display in a UI
formatEther(eth)
//_result:
// Convert a value in wei to a string in gwei to display in a UI
formatUnits(feePerGas, "gwei")
//_result:
_subsection: Contracts
_heading: Read-only methods (i.e. ``view`` and ``pure``)
_heading: State-changing Methods
_heading: Estimating Gas and fees
_heading: Listening to Events
_heading: Query Historic Events
_subsection: Signing Messages