Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README update: usage example with new wallet args #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ npm install --save @project-serum/sol-wallet-adapter
```js
import { Connection, SystemProgram, Transaction, clusterApiUrl } from '@solana/web3.js';

let connection = new Connection(clusterApiUrl('devnet'));
const network = clusterApiUrl('devnet');
let connection = new Connection(network);
let providerUrl = 'https://www.sollet.io';
let wallet = new Wallet(providerUrl);
let wallet = new Wallet(providerUrl, network);
wallet.on('connect', publicKey => console.log('Connected to ' + publicKey.toBase58()));
wallet.on('disconnect', () => console.log('Disconnected'));
await wallet.connect();

// In call SystemProgram.transfer, TransferParams type requires a not null publicKey
if (wallet.publicKey == null) {
throw new Error('wallet not connected');
}

let transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: wallet.publicKey,
Expand All @@ -40,13 +46,16 @@ let txid = await connection.sendRawTransaction(signed.serialize());
await connection.confirmTransaction(txid);
```

See [example/src/App.js](https://github.com/serum-foundation/sol-wallet-adapter/blob/master/example/src/App.js) for a full example.
See [example/src/App.tsx](https://github.com/serum-foundation/sol-wallet-adapter/blob/master/example/src/App.tsx) for a full example.

### Sign a message

```js
import { Connection, SystemProgram, Transaction, clusterApiUrl } from '@solana/web3.js';

const network = clusterApiUrl('devnet');
const providerUrl = 'https://www.sollet.io';
const wallet = new Wallet(providerUrl);
const wallet = new Wallet(providerUrl, network);
wallet.on('connect', publicKey => console.log('Connected to ' + publicKey.toBase58()));
wallet.on('disconnect', () => console.log('Disconnected'));
await wallet.connect();
Expand Down