-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: migrate other half of the wallet snippets (#3365)
* docs: convert old wallet snippets * docs: split snippets * docs: update snippets * docs: ensure test is node only * docs: add node group at the bottom * remove old import Co-authored-by: Peter Smith <[email protected]> * remove old import Co-authored-by: Peter Smith <[email protected]> * remove space Co-authored-by: Peter Smith <[email protected]> * adjust imports in snippet Co-authored-by: Peter Smith <[email protected]> * remove old import Co-authored-by: Peter Smith <[email protected]> * docs: remove old import * docs: update snippet test suffix * docs: move snippets into wallet guide * docs: update snippets comment Co-authored-by: Daniel Bate <[email protected]> * docs: remove unnecessary full examples * linting fixes * docs: add try/catch to snippet * docs: add defaultConnectors + remove unused snippet * dep: patch temp issue with knip * docs: update to use mocked deps --------- Co-authored-by: Peter Smith <[email protected]> Co-authored-by: Daniel Bate <[email protected]>
- Loading branch information
1 parent
8c77765
commit 63a34f6
Showing
26 changed files
with
451 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
apps/docs-snippets/src/guide/wallets/checking-balances-and-coins.test.ts
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
apps/docs-snippets/src/guide/wallets/checking-balances.test.ts
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
apps/docs-snippets/src/guide/wallets/encrypting-and-decrypting-json-wallets.test.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// #region full | ||
// #region wallets | ||
import type { WalletLocked, WalletUnlocked } from 'fuels'; | ||
import { Provider, Wallet } from 'fuels'; | ||
|
||
import { LOCAL_NETWORK_URL } from '../env'; | ||
|
||
// We can use the `generate` to create a new unlocked wallet. | ||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
const myWallet: WalletUnlocked = Wallet.generate({ provider }); | ||
|
||
// or use an Address to create a wallet | ||
const someWallet: WalletLocked = Wallet.fromAddress(myWallet.address, provider); | ||
// #endregion wallets | ||
|
||
const wallet: WalletUnlocked = Wallet.generate({ provider }); | ||
const PRIVATE_KEY = wallet.privateKey; | ||
|
||
// Lock an existing wallet | ||
const lockedWallet: WalletLocked = Wallet.fromAddress( | ||
myWallet.address, | ||
provider | ||
); | ||
|
||
// Unlock an existing wallet | ||
const someUnlockedWallet: WalletUnlocked = lockedWallet.unlock(PRIVATE_KEY); | ||
|
||
const unlockedWallet: WalletUnlocked = Wallet.generate({ provider }); | ||
const newlyLockedWallet = unlockedWallet.lock(); | ||
|
||
// You can create a wallet, without a provider | ||
let unlockedWalletWithoutProvider: WalletUnlocked = Wallet.generate(); | ||
unlockedWalletWithoutProvider = Wallet.fromPrivateKey( | ||
unlockedWalletWithoutProvider.privateKey | ||
); | ||
|
||
// All non-provider dependent methods are available | ||
unlockedWalletWithoutProvider.lock(); | ||
|
||
// All provider dependent methods will throw | ||
await expect(() => unlockedWalletWithoutProvider.getCoins()).rejects.toThrow( | ||
/Provider not set/ | ||
); | ||
// #endregion full |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// #region checking-balances-2 | ||
import { Provider, Wallet } from 'fuels'; | ||
|
||
import { WALLET_PVT_KEY_2, LOCAL_NETWORK_URL } from '../env'; | ||
|
||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
const myOtherWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY_2, provider); | ||
|
||
const { balances } = await myOtherWallet.getBalances(); | ||
// #endregion checking-balances-2 | ||
console.log('balances:', balances); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// #region checking-balances-1 | ||
import type { BN } from 'fuels'; | ||
import { Provider, Wallet } from 'fuels'; | ||
|
||
import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../env'; | ||
|
||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
|
||
const myWallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); | ||
|
||
// The returned amount is a BigNumber | ||
const balance: BN = await myWallet.getBalance(provider.getBaseAssetId()); | ||
|
||
// #endregion checking-balances-1 | ||
console.log('balance', balance); |
Oops, something went wrong.