Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/phan-wallet-mock
🪙 Mock version of Phantom Wallet. ONLY USE FOR TESTING!!!
https://github.com/thlorenz/phan-wallet-mock
Last synced: 21 days ago
JSON representation
🪙 Mock version of Phantom Wallet. ONLY USE FOR TESTING!!!
- Host: GitHub
- URL: https://github.com/thlorenz/phan-wallet-mock
- Owner: thlorenz
- Created: 2021-11-09T16:02:20.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-24T13:23:40.000Z (almost 3 years ago)
- Last Synced: 2024-10-12T05:21:43.235Z (25 days ago)
- Language: TypeScript
- Homepage: https://thlorenz.github.io/phan-wallet-mock/docs/
- Size: 873 KB
- Stars: 7
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# phan-wallet-mock [![Build and Test](https://github.com/thlorenz/phan-wallet-mock/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/thlorenz/phan-wallet-mock/actions/workflows/build-and-test.yml)
Mock version of Phantom Wallet. **ONLY USE FOR TESTING!!!**
```ts
export async function setupWithPayer(
payer = Keypair.generate(),
net = LOCALNET
): Promise<{ payer: Keypair; wallet: PhantomWalletMock }> {
const wallet = PhantomWalletMock.create(net, payer, 'confirmed')// NOTE: no user approval needed
await wallet.connect()
const signature = await wallet.connection.requestAirdrop(
payer.publicKey,
LAMPORTS_PER_SOL * 5
)
// NOTE: no user approval needed here either
await wallet.connection.confirmTransaction(signature)return { payer, wallet }
}const { wallet, payer } = await setupWithPayer()
// NOTE: this only works when no actual Phantom extension is present as then `window.solana`
// cannot be overwritten
window.solana = wallet
```![assets/cypress.png](assets/cypress.png)
## API
[API documentation](https://thlorenz.github.io/phan-wallet-mock/docs/index.html)
## How it Works
Unlike with real wallets `phan-wallet-mock` requires the user to provide a full `Keypair` which
it uses under the hood to sign transactions and messages.To do that it never requires the user's approval like the original does in order to ease
testing.**THEREFORE MAKE SURE TO ONLY USE THIS WHILE RUNNING TESTS WITH FRESHLY GENERATED KEYPAIRS!!!**
## Apps using phan-wallet-mock
- [example app based on phantom wallet
sandbox](https://github.com/thlorenz/phan-wallet-mock-react-example)## LICENSE
MIT