docs: fixed typos and updated examples

This commit is contained in:
Richard Moore 2021-06-23 23:40:50 -04:00
parent d001901c8c
commit 17af9f812f
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
3 changed files with 74 additions and 9 deletions

View File

@ -52,21 +52,21 @@ _heading: Output Formats @<fragments--output-formats> @SRC<abi/fragments:FormatT
Each [[Fragment]] and [[ParamType]] may be output using its ``format``
method.
_property: ethers.utils.FragmentTypes.full => string
_property: ethers.utils.FormatTypes.full => string
This is a full human-readable string, including all parameter names, any
optional modifiers (e.g. ``indexed``, ``public``, etc) and white-space
to aid in human readability.
_property: ethers.utils.FragmentTypes.minimal => string
_property: ethers.utils.FormatTypes.minimal => string
This is similar to ``full``, except with no unnecessary whitespace or parameter
names. This is useful for storing a minimal string which can still fully
reconstruct the original Fragment using [Fragment&thinsp;.&thinsp;from](Fragment-from).
_property: ethers.utils.FragmentTypes.json => string
_property: ethers.utils.FormatTypes.json => string
This returns a JavaScript Object which is safe to call ``JSON.stringify``
on to create a JSON string.
_property: ethers.utils.FragmentTypes.sighash => string
_property: ethers.utils.FormatTypes.sighash => string
This is a minimal output format, which is used by Solidity when computing a
signature hash or an event topic hash.
@ -74,6 +74,9 @@ _warning: Note
The ``sighash`` format is **insufficient** to re-create the original [[Fragment]],
since it discards modifiers such as indexed, anonymous, stateMutability, etc.
It is only useful for computing the selector for a Fragment, and cannot
be used to format an Interface.
_subsection: Fragment @<Fragment> @SRC<abi/fragments:class.Fragment>
An ABI is a collection of **Fragments**, where each fragment specifies:

View File

@ -33,12 +33,28 @@ _code: Creating an Interface instance @lang<javascript>
// This interface is used for the below examples
const iface = new Interface([
// Constructor
"constructor(string symbol, string name)",
// State mutating method
"function transferFrom(address from, address to, uint amount)",
"function balanceOf(address owner) view returns (uint)",
// State mutating method, which is payable
"function mint(uint amount) payable",
// Constant method (i.e. "view" or "pure")
"function balanceOf(address owner) view returns (uint)",
// An Event
"event Transfer(address indexed from, address indexed to, uint256 amount)",
"error AccountLocked(address owner, uint256 balance)"
// A Custom Solidity Error
"error AccountLocked(address owner, uint256 balance)",
// Examples with structured types
"function addUser(tuple(string name, address addr) user) returns (uint id)",
"function addUsers(tuple(string name, address addr)[] user) returns (uint[] id)",
"function getUser(uint id) view returns (tuple(string name, address addr) user)"
]);
//_hide: _page.iface = iface;
@ -263,6 +279,25 @@ iface.encodeFunctionData("transferFrom", [
])
//_log:
// Encoding structured data (using positional Array)
user = [
"Richard Moore",
"0x8ba1f109551bD432803012645Ac136ddd64DBA72"
];
//_result:
iface.encodeFunctionData("addUser", [ user ]);
//_log:
// Encoding structured data, using objects. Only available
// if paramters are named.
user = {
name: "Richard Moore",
addr: "0x8ba1f109551bD432803012645Ac136ddd64DBA72"
};
//_result:
iface.encodeFunctionData("addUser", [ user ]);
//_log:
_property: interface.encodeFunctionResult(fragment [ , values ]) => string<[[DataHexString]]> @SRC<abi/interface>
Returns the encoded result, which would normally be the response from a call for
//fragment// (see [[Interface--specifying-fragments]]) for the given //values//.
@ -342,18 +377,37 @@ _code: @lang<javascript>
//_hide: const iface = _page.iface;
// Decoding result data (e.g. from an eth_call)
const resultData = "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000";
resultData = "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000";
//_result:
iface.decodeFunctionResult("balanceOf", resultData)
//_log:
// Decoding result data which was caused by a revert
// Throws a CALL_EXCEPTION, with extra details
const errorData = "0xf7c3865a0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba720000000000000000000000000000000000000000000000000de0b6b3a7640000";
errorData = "0xf7c3865a0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba720000000000000000000000000000000000000000000000000de0b6b3a7640000";
//_throws:
iface.decodeFunctionResult("balanceOf", errorData)
//_log:
// Decoding structured data returns a Result object, which
// will include all values positionally and if the ABI
// included names, values will additionally be available
// by their name.
resultData = "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72000000000000000000000000000000000000000000000000000000000000000d52696368617264204d6f6f726500000000000000000000000000000000000000";
//_result:
result = iface.decodeFunctionResult("getUser", resultData);
//_log:
// Access positionally:
// The 0th output parameter, the 0th proerty of the structure
//_result:
result[0][0];
//_log:
// Access by name: (only avilable because parameters were named)
//_result:
result.user.name
//_log:
_subsection: Parsing @<Interface--parsing>

View File

@ -179,12 +179,20 @@ function codeContextify(context) {
sorted: true,
});
}
context._startup = function() {
console.log("Startup");
}
context._shutdown = function() {
console.log("Shutdown");
}
}
module.exports = {
title: "ethers",
subtitle: "v5.2",
subtitle: "v5.3",
description: "Documentation for ethers, a complete, tiny and simple Ethereum library.",
logo: "logo.svg",