Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jun 16, 2024
1 parent 956b88d commit 4831b1a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ For [Deno](https://deno.land), ensure to use [npm specifier](https://deno.land/m
For React Native, you may need a [polyfill for getRandomValues](https://github.com/LinusU/react-native-get-random-values).
If you don't like NPM, a standalone [eth-signer.js](https://github.com/paulmillr/micro-eth-signer/releases) is also available.

- [Create random wallet](#create-random-wallet)
- [Transactions: create, sign](#create-and-sign-transactions)
- [Addresses: create, checksum](#create-and-checksum-addresses)
- [Create random wallet](#create-random-wallet)
- [Network and smart contracts](#network-and-smart-contracts)
- [Fetch balances and history from an archive node](#fetch-balances-and-history-from-an-archive-node)
- [Fetch Chainlink oracle prices](#fetch-chainlink-oracle-prices)
Expand All @@ -45,22 +45,30 @@ If you don't like NPM, a standalone [eth-signer.js](https://github.com/paulmillr
- [Performance](#performance)
- [License](#license)

### Create random wallet

```ts
import { addr } from 'micro-eth-signer';
const random = addr.random(); // Secure: uses CSPRNG
console.log(random.privateKey, random.address);
// '0x17ed046e6c4c21df770547fad9a157fd17b48b35fe9984f2ff1e3c6a62700bae'
// '0x26d930712fd2f612a107A70fd0Ad79b777cD87f6'
```

### Transactions: create, sign

```ts
import { addr, Transaction, weigwei, weieth } from 'micro-eth-signer';
const privKey = '0x6b911fd37cdf5c81d4c0adb1ab7fa822ed253ab0ad9aa18d77257c88b29b718e';
const senderAddr = addr.fromPrivateKey(privKey);
const unsignedTx = Transaction.prepare({
import { Transaction, weigwei, weieth } from 'micro-eth-signer';
const tx = Transaction.prepare({
to: '0xdf90dea0e0bf5ca6d2a7f0cb86874ba6714f463e',
maxFeePerGas: weigwei.decode('100'), // 100 gwei in wei
value: weieth.decode('1.1'), // 1.1 eth in wei
value: weieth.decode('1.1'), // 1.1eth in wei
maxFeePerGas: weigwei.decode('100'), // 100gwei in wei (priority fee is 1 gwei)
nonce: 0n,
});
const tx = unsignedTx.signBy(privKey); // Uint8Array is also accepted
console.log('signed tx', tx, tx.toHex());
console.log('need total', tx.calcAmounts()); // wei & humanized formats
console.log('address is same', tx.sender === senderAddr);
// Uses `random` from example above. Alternatively, pass 0x hex string or Uint8Array
const signedTx = tx.signBy(random.privateKey);
console.log('signed tx', signedTx, signedTx.toHex());
console.log('need total', signedTx.calcAmounts()); // wei & humanized formats
```

We support legacy, EIP2930, EIP1559 and EIP4844 (Dencun / Cancun) transactions.
Expand All @@ -82,16 +90,6 @@ console.log(
);
```

### Create random wallet

```ts
import { addr } from 'micro-eth-signer';
const random = addr.random(); // Secure: uses CSPRNG
console.log(random.privateKey, random.address);
// 0x17ed046e6c4c21df770547fad9a157fd17b48b35fe9984f2ff1e3c6a62700bae
// 0x26d930712fd2f612a107A70fd0Ad79b777cD87f6
```

### Network and smart contracts

We don't have _actual network code_ in the package:
Expand Down Expand Up @@ -354,9 +352,9 @@ EIP-712 is not supported yet.

```ts
import { addr, messenger } from 'micro-eth-signer';
const { privateKey, address } = addr.random();
const rand = addr.random();
const msg = 'noble';
const sig = messenger.sign(msg, privateKey);
const sig = messenger.sign(msg, rand.privateKey);
const isValid = messenger.verify(sig, msg, address);
```

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
"default": "./net/index.js"
},
"./rlp": {
"types": "./net/rlp.d.ts",
"import": "./esm/net/rlp.js",
"default": "./net/rlp.js"
"types": "./rlp.d.ts",
"import": "./esm/rlp.js",
"default": "./rlp.js"
},
"./ssz": {
"types": "./net/ssz.d.ts",
"import": "./esm/net/ssz.js",
"types": "./ssz.d.ts",
"import": "./esm/ssz.js",
"default": "./net/ssz.js"
},
"./tx": {
Expand Down
3 changes: 3 additions & 0 deletions src/net/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ export class ArchiveNodeProvider {
async height(): Promise<number> {
return Number.parseInt(await this.rpc('eth_blockNumber'));
}
async maxPriorityFeePerGas(): Promise<BigInt> {
return BigInt(await this.rpc('eth_maxPriorityFeePerGas'));
}

async traceFilterSingle(address: string, opts: TraceOpts = {}) {
const res = await this.rpc('trace_filter', {
Expand Down

0 comments on commit 4831b1a

Please sign in to comment.