-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
170 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
src/examples/getting-started-active-account-events.beacon.ts
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,25 @@ | ||
/// START | ||
import { BeaconEvent, DAppClient } from "@airgap/beacon-sdk"; | ||
/// END | ||
|
||
async () => { | ||
/// START | ||
const dAppClient = new DAppClient({ name: "Beacon Docs" }); | ||
|
||
// Listen for all the active account changes | ||
dAppClient.subscribeToEvent( | ||
BeaconEvent.ACTIVE_ACCOUNT_SET, | ||
async (account) => { | ||
// An active account has been set, update the dApp UI | ||
console.log(`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `, account); | ||
} | ||
); | ||
|
||
// Check if we are connected. If not, do a permission request first. | ||
const activeAccount = await dAppClient.getActiveAccount(); | ||
if (!activeAccount) { | ||
await dAppClient.requestPermissions(); | ||
} | ||
|
||
/// END | ||
}; |
20 changes: 20 additions & 0 deletions
20
src/examples/getting-started-active-account-events.taquito.ts
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,20 @@ | ||
/// START | ||
import { TezosToolkit } from "@taquito/taquito"; | ||
import { BeaconWallet } from "@taquito/beacon-wallet"; | ||
import { BeaconEvent } from "@airgap/beacon-sdk"; | ||
/// END | ||
|
||
async () => { | ||
/// START | ||
const Tezos = new TezosToolkit("https://mainnet-tezos.giganode.io"); | ||
const wallet = new BeaconWallet({ name: "Beacon Docs Taquito" }); | ||
|
||
Tezos.setWalletProvider(wallet); | ||
|
||
wallet.client.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, (account) => { | ||
// An active account has been set | ||
console.log(`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `, account); | ||
}); | ||
|
||
/// END | ||
}; |
43 changes: 43 additions & 0 deletions
43
src/examples/getting-started-operation-request-events.beacon.ts
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,43 @@ | ||
/// START | ||
import { | ||
BeaconEvent, | ||
DAppClient, | ||
TezosOperationType, | ||
} from "@airgap/beacon-sdk"; | ||
/// END | ||
|
||
async () => { | ||
/// START | ||
const dAppClient = new DAppClient({ name: "Beacon Docs" }); | ||
|
||
// Listen for all the active account changes | ||
dAppClient.subscribeToEvent( | ||
BeaconEvent.ACTIVE_ACCOUNT_SET, | ||
async (account) => { | ||
// An active account has been set, update the dApp UI | ||
console.log(`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `, account); | ||
|
||
// At this point we are connected to an account. | ||
// Let's send a simple transaction to the wallet that sends 1 mutez to ourselves. | ||
const response = await dAppClient.requestOperation({ | ||
operationDetails: [ | ||
{ | ||
kind: TezosOperationType.TRANSACTION, | ||
destination: account.address, // Send to ourselves | ||
amount: "1", // Amount in mutez, the smallest unit in Tezos | ||
}, | ||
], | ||
}); | ||
|
||
console.log(response); | ||
} | ||
); | ||
|
||
// Check if we are connected. If not, do a permission request first. | ||
const activeAccount = await dAppClient.getActiveAccount(); | ||
if (!activeAccount) { | ||
await dAppClient.requestPermissions(); | ||
} | ||
|
||
/// END | ||
}; |
46 changes: 46 additions & 0 deletions
46
src/examples/getting-started-operation-request-events.taquito.ts
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,46 @@ | ||
/// START | ||
import { TezosToolkit } from "@taquito/taquito"; | ||
import { BeaconWallet } from "@taquito/beacon-wallet"; | ||
import { | ||
BeaconEvent, | ||
DAppClient, | ||
TezosOperationType, | ||
} from "@airgap/beacon-sdk"; | ||
/// END | ||
|
||
async () => { | ||
/// START | ||
const Tezos = new TezosToolkit("https://mainnet-tezos.giganode.io"); | ||
const wallet = new BeaconWallet({ name: "Beacon Docs Taquito" }); | ||
|
||
Tezos.setWalletProvider(wallet); | ||
|
||
// Listen for all the active account changes | ||
wallet.client.subscribeToEvent( | ||
BeaconEvent.ACTIVE_ACCOUNT_SET, | ||
async (account) => { | ||
// An active account has been set, update the dApp UI | ||
console.log(`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `, account); | ||
|
||
// At this point we are connected to an account. | ||
// Let's send a simple transaction to the wallet that sends 1 mutez to ourselves. | ||
const response = await wallet.sendOperations([ | ||
{ | ||
kind: TezosOperationType.TRANSACTION, | ||
destination: account.address, // Send to ourselves | ||
amount: "1", // Amount in mutez, the smallest unit in Tezos | ||
}, | ||
]); | ||
|
||
console.log(response); | ||
} | ||
); | ||
|
||
// Check if we are connected. If not, do a permission request first. | ||
const activeAccount = await wallet.client.getActiveAccount(); | ||
if (!activeAccount) { | ||
await wallet.client.requestPermissions(); | ||
} | ||
|
||
/// END | ||
}; |