diff --git a/mini-apps/api-reference/ethereum-provider.md b/mini-apps/api-reference/ethereum-provider.md index 8b9a9bd9..8fd78839 100644 --- a/mini-apps/api-reference/ethereum-provider.md +++ b/mini-apps/api-reference/ethereum-provider.md @@ -2,7 +2,7 @@ -# Ethereum Provider API (window.ethereum) +# Ethereum Provider API This provider implements [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and supports [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963) provider discovery. It is injected into the mini app environment. diff --git a/mini-apps/api-reference/index.md b/mini-apps/api-reference/index.md index 6cfbb435..530d3e7d 100644 --- a/mini-apps/api-reference/index.md +++ b/mini-apps/api-reference/index.md @@ -4,7 +4,7 @@ # API Reference -This API is injected by the host app into the mini app environment. The providers are available on the `window` object. This section is reference-only. +This API is injected by the host app into the mini app environment. For Nimiq access, the recommended pattern is to use the Mini App SDK `init()` helper. This section is reference-only. ## Contents @@ -17,14 +17,15 @@ To load and build a mini app, see [Load a Local Mini App in Nimiq Pay](https://n ### Nimiq Provider -```javascript -const nimiq = window.nimiq +```typescript +import { init } from '@nimiq/mini-app-sdk' -const accounts = await nimiq.listAccounts() -const address = accounts[0] +const nimiq = await init() +const accounts = await nimiq.listAccounts() const signed = await nimiq.sign('hello') -console.log({ address, signed }) + +console.log({ accounts, signed }) ``` ### Ethereum dApp (EIP-1193) diff --git a/mini-apps/api-reference/nimiq-provider.md b/mini-apps/api-reference/nimiq-provider.md index 00aa9b2d..8f573e7d 100644 --- a/mini-apps/api-reference/nimiq-provider.md +++ b/mini-apps/api-reference/nimiq-provider.md @@ -2,14 +2,18 @@ -# Nimiq Provider API (window.nimiq) +# Nimiq Provider API This provider exposes Nimiq blockchain operations and is injected into the mini app environment. ## Access -```javascript -const nimiq = window.nimiq +Use the Mini App SDK `init()` helper to wait until Nimiq Pay injects the provider. + +```ts +import { init } from '@nimiq/mini-app-sdk' + +const nimiq = await init() ``` ## Methods @@ -36,7 +40,7 @@ Returns the user's Nimiq account addresses. **Example** -```javascript +```ts const accounts = await nimiq.listAccounts() ``` @@ -62,7 +66,7 @@ Signs a message with the user's Nimiq key. **Example** -```javascript +```ts const signed = await nimiq.sign('hello') ``` @@ -84,7 +88,7 @@ Checks whether the Nimiq network consensus is established. **Example** -```javascript +```ts const ready = await nimiq.isConsensusEstablished() ``` @@ -106,7 +110,7 @@ Returns the current Nimiq block height. **Example** -```javascript +```ts const height = await nimiq.getBlockNumber() ``` @@ -119,6 +123,7 @@ Sends a basic NIM payment. - `recipient` (string, required): Nimiq user-friendly address. - `value` (number, required): amount in Luna (1 NIM = 100,000 Luna). - `fee` (number, optional): transaction fee in Luna. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -135,10 +140,14 @@ Sends a basic NIM payment. **Example** -```javascript +```ts const txHash = await nimiq.sendBasicTransaction({ recipient: 'NQ07 0000 0000 0000 0000 0000 0000 0000 0000', value: 100000, + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. + fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` @@ -151,7 +160,8 @@ Sends a NIM payment with an attached text message. - `recipient` (string, required): Nimiq user-friendly address. - `value` (number, required): amount in Luna (1 NIM = 100,000 Luna). - `fee` (number, optional): transaction fee in Luna. -- `data` (string, optional): text message to attach. +- `data` (string, required): text message to attach. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -168,11 +178,15 @@ Sends a NIM payment with an attached text message. **Example** -```javascript +```ts const txHash = await nimiq.sendBasicTransactionWithData({ recipient: 'NQ07 0000 0000 0000 0000 0000 0000 0000 0000', value: 100000, data: 'mic check', + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. + fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` @@ -184,7 +198,8 @@ Creates a new staking transaction. - `delegation` (string, required): validator address or delegation target. - `value` (number, required): amount in Luna. -- `fee` (number, required): transaction fee in Luna. +- `fee` (number, optional): transaction fee in Luna. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -201,22 +216,26 @@ Creates a new staking transaction. **Example** -```javascript +```ts const txHash = await nimiq.sendNewStakerTransaction({ delegation: 'NQ07 0000 0000 0000 0000 0000 0000 0000 0000', value: 100000, + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` -### `sendAddStakeTransaction` +### `sendStakeTransaction` Adds stake to an existing staker. **Parameters** - `value` (number, required): amount in Luna. -- `fee` (number, required): transaction fee in Luna. +- `fee` (number, optional): transaction fee in Luna. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -233,10 +252,13 @@ Adds stake to an existing staker. **Example** -```javascript -const txHash = await nimiq.sendAddStakeTransaction({ +```ts +const txHash = await nimiq.sendStakeTransaction({ value: 100000, + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` @@ -247,7 +269,8 @@ Sets the active stake amount. **Parameters** - `newActiveBalance` (number, required): active stake amount in Luna. -- `fee` (number, required): transaction fee in Luna. +- `fee` (number, optional): transaction fee in Luna. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -264,10 +287,13 @@ Sets the active stake amount. **Example** -```javascript +```ts const txHash = await nimiq.sendSetActiveStakeTransaction({ newActiveBalance: 100000, + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` @@ -278,8 +304,9 @@ Updates staker settings. **Parameters** - `newDelegation` (string, required): new validator address or delegation target. -- `reactivateAllStake` (boolean, required): whether to reactivate all stake. -- `fee` (number, required): transaction fee in Luna. +- `reactivateAllStake` (boolean, optional): whether to reactivate all stake. +- `fee` (number, optional): transaction fee in Luna. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -296,11 +323,14 @@ Updates staker settings. **Example** -```javascript +```ts const txHash = await nimiq.sendUpdateStakerTransaction({ newDelegation: 'NQ07 0000 0000 0000 0000 0000 0000 0000 0000', reactivateAllStake: true, + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` @@ -311,7 +341,8 @@ Retires stake from a staker. **Parameters** - `retireStake` (number, required): amount in Luna to retire. -- `fee` (number, required): transaction fee in Luna. +- `fee` (number, optional): transaction fee in Luna. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -328,10 +359,13 @@ Retires stake from a staker. **Example** -```javascript +```ts const txHash = await nimiq.sendRetireStakeTransaction({ retireStake: 100000, + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` @@ -342,7 +376,8 @@ Removes stake from a staker. **Parameters** - `value` (number, required): amount in Luna. -- `fee` (number, required): transaction fee in Luna. +- `fee` (number, optional): transaction fee in Luna. +- `validityStartHeight` (number, optional): block height from which the transaction becomes valid. **Returns** @@ -359,9 +394,12 @@ Removes stake from a staker. **Example** -```javascript +```ts const txHash = await nimiq.sendRemoveStakeTransaction({ value: 100000, + // Optional. Nimiq Pay chooses a fee automatically, using 0 if possible. fee: 1000, + // Optional. + validityStartHeight: 123456, }) ``` diff --git a/mini-apps/dual-chain-mini-app-tutorial.md b/mini-apps/dual-chain-mini-app-tutorial.md index cbc2a770..64538593 100644 --- a/mini-apps/dual-chain-mini-app-tutorial.md +++ b/mini-apps/dual-chain-mini-app-tutorial.md @@ -12,8 +12,8 @@ In this tutorial, you will build a mini app that uses both injected providers: -- `window.nimiq` for Nimiq account and signing flows -- `window.ethereum` for EIP-1193 account and signing flows +- the Nimiq provider for Nimiq account and signing flows +- the Ethereum provider for EIP-1193 account and signing flows You will implement methods that require user confirmations so you can test real wallet interactions end to end. @@ -60,20 +60,24 @@ export default defineConfig({ }) ``` -## 5. Add the dual-chain mini app +## 5. Install the Nimiq Mini App SDK + +Install the published Nimiq Mini App SDK before editing `src/App.vue`. + +```bash +npm install @nimiq/mini-app-sdk +``` + +## 6. Add the dual-chain mini app In `src/App.vue`, use separate script, template, and style blocks. -### 5.1 Add the script block +### 6.1 Add the script block ```vue ``` -### 5.2 Add the template block +### 6.2 Add the template block ```vue ``` -### 5.3 Add the style block (mobile-friendly) +### 6.3 Add the style block (mobile-friendly) ```vue ``` -## 6. Run the mini app +## 7. Run the mini app ```bash npm run dev -- --host @@ -290,7 +343,7 @@ Copy the **Network** URL from the terminal output, for example: http://192.168.1.42:5173 ``` -## 7. Test inside Nimiq Pay +## 8. Test inside Nimiq Pay 1. Make sure your phone and dev machine are on the same Wi‑Fi network. 2. Open **Nimiq Pay**. @@ -304,7 +357,7 @@ You should see: - Nimiq accounts and a Nimiq signature response. - Ethereum account(s) and an Ethereum signature response. -## 8. Troubleshooting +## 9. Troubleshooting **No Ethereum account returned**\ The Ethereum success path requires at least one account available through Nimiq Pay. diff --git a/mini-apps/mini-app-tutorial.md b/mini-apps/mini-app-tutorial.md index 0cc3c019..d53ed29e 100644 --- a/mini-apps/mini-app-tutorial.md +++ b/mini-apps/mini-app-tutorial.md @@ -10,7 +10,7 @@ > - On iOS, share the email associated with your Apple account. Install TestFlight, and the Nimiq Pay test build will appear there once your account is allowlisted. > - On Android, share the email associated with your Google account. You will receive an email when access is enabled. -In this tutorial, you’ll build a minimal mini app that runs inside Nimiq Pay and calls three Nimiq provider methods: +In this tutorial, you'll build a minimal mini app that runs inside Nimiq Pay and calls three Nimiq provider methods: | Method | Description | | --- | --- | @@ -44,7 +44,15 @@ npm install ::: -## 2. Configure the dev server +## 2. Install the Nimiq Mini App SDK + +Install the Nimiq Mini App SDK. For package details, see [`@nimiq/mini-app-sdk`](https://www.npmjs.com/package/@nimiq/mini-app-sdk). + +```bash +npm install @nimiq/mini-app-sdk +``` + +## 3. Configure the dev server Enable network access so Nimiq Pay on your device can reach the app: @@ -91,7 +99,7 @@ export default defineConfig({ ::: -## 3. Add mini app logic and UI +## 4. Add mini app logic and UI Replace the main app component with the variant for your framework: @@ -99,57 +107,61 @@ Replace the main app component with the variant for your framework: ```vue [Vue + Vite (src/App.vue)]