Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mini-apps/api-reference/ethereum-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- type: api reference -->
<!-- summary: Reference for the EIP-1193 Ethereum provider injected into mini apps, including EIP-6963 compatibility -->

# 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.

Expand Down
13 changes: 7 additions & 6 deletions mini-apps/api-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
88 changes: 63 additions & 25 deletions mini-apps/api-reference/nimiq-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<!-- type: api reference -->
<!-- summary: Reference for the Nimiq provider injected into mini apps -->

# 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
Expand All @@ -36,7 +40,7 @@ Returns the user's Nimiq account addresses.

**Example**

```javascript
```ts
const accounts = await nimiq.listAccounts()
```

Expand All @@ -62,7 +66,7 @@ Signs a message with the user's Nimiq key.

**Example**

```javascript
```ts
const signed = await nimiq.sign('hello')
```

Expand All @@ -84,7 +88,7 @@ Checks whether the Nimiq network consensus is established.

**Example**

```javascript
```ts
const ready = await nimiq.isConsensusEstablished()
```

Expand All @@ -106,7 +110,7 @@ Returns the current Nimiq block height.

**Example**

```javascript
```ts
const height = await nimiq.getBlockNumber()
```

Expand All @@ -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**

Expand All @@ -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,
})
```

Expand All @@ -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**

Expand All @@ -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,
})
```

Expand All @@ -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**

Expand All @@ -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**

Expand All @@ -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,
})
```

Expand All @@ -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**

Expand All @@ -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,
})
```

Expand All @@ -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**

Expand All @@ -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,
})
```

Expand All @@ -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**

Expand All @@ -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,
})
```

Expand All @@ -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**

Expand All @@ -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,
})
```
Loading
Loading