owned this note
owned this note
Published
Linked with GitHub
# Mimir Wallet API Documentation
## Batch Transaction API
Add a batch transaction for later execution.
### Endpoint
```http
POST /v1/chains/:chain_name/:multisig_address/transactions/batch/add
```
### Path Parameters
| Parameter | Type | Description |
| ---------------- | ------ | ------------------------------------------------ |
| chain_name | string | The target blockchain network |
| multisig_address | string | The multisig wallet address (ss58 or public key) |
### Supported Networks (`chain_name`)
#### Polkadot Ecosystem
- `polkadot` - Polkadot Main Network
- `assethub-polkadot` - Polkadot Asset Hub
- `coretime-polkadot` - Polkadot Coretime
- `collectives-polkadot` - Polkadot Collectives
- `people-polkadot` - Polkadot People
#### Kusama Ecosystem
- `kusama` - Kusama Network
- `assethub-kusama` - Kusama Asset Hub
- `people-kusama` - Kusama People
#### Other Networks
- `paseo` - Paseo Network
### Multisig Address Format
The `multisig_address` can be provided in two formats:
1. **Public Key (hex)**
```
0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b
```
2. **SS58 Address**
```
16ZL8yLyXv3V3L3z9ofR1ovFLziyXaN1DPq4yffMAZ9czzBD
```
### Request Body
```typescript
interface BatchTransactionRequest {
calldata: string; // Hex-encoded transaction data
signature: string; // Hex-encoded signature
timestamp: number; // Current timestamp in milliseconds
signer: string // signer of signature, ss58 or public key, must be multisig owner of proposer
}
```
#### Fields Description
| Field | Type | Required | Description |
| --------- | ------ | -------- | -------------------------------------------------------- |
| calldata | string | Yes | Hex-encoded transaction data to be executed |
| signature | string | Yes | Hex-encoded signature from a multisig member or proposer |
| timestamp | number | Yes | Current Unix timestamp in milliseconds |
| signer | string | Yes | signer of signature, must be multisig owner of proposer |
#### Signature Requirements
- The signature must be created by a valid multisig member or proposer
- The signature payload must follow the specified format below
- The signature must be fresh (timestamp within acceptable range)
`signMessage = "Sign for mimir batch\n" + "Call Data: ${calldata}\n" + "Address: ${multisigAddress}\n" + "Timestamp: ${timestamp}"`
### Example Implementation(typescript)
```typescript
import { createTestKeyring } from '@polkadot/keyring';
import { u8aToHex } from '@polkadot/util';
import { cryptoWaitReady, encodeMultiAddress } from '@polkadot/util-crypto';
const batchTransaction = async () => {
// Wait for crypto to be ready
await cryptoWaitReady();
// Initialize keyring and accounts
const keyring = createTestKeyring();
const alice = keyring.getPairs()[0];
const bob = keyring.getPairs()[1];
// Configuration
const config = {
clientGateway: 'https://mimir-client.mimir.global', // Replace with actual API endpoint
chain: 'polkadot'
};
const calldata = '0x000000'; // Example: system.remark, replace with actual calldata
// Create multisig address
const multisigAddress = encodeMultiAddress(
[alice.address, bob.address],
2 // Threshold
);
// Prepare request payload
const payload = {
calldata: calldata,
timestamp: Date.now()
};
// Create signature
const message = [
'Sign for mimir batch\n',
`Call Data: ${payload.calldata}\n`,
`Address: ${multisigAddress}\n`,
`Timestamp: ${payload.timestamp}`
].join('');
const signature = alice.sign(message);
const signatureHex = u8aToHex(signature);
// Prepare final request
const request = {
...payload,
signature: signatureHex,
signer: alice.address
};
// Send request
try {
const response = await fetch(
`${config.clientGateway}/v1/chains/${config.chain}/${multisigAddress}/transactions/batch`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
}
);
const result = await response.json();
return result;
} catch (error) {
console.error('Failed to upload transaction:', error);
throw error;
}
};
```
### Response Format
success when httpStatus is 200, otherwise failure
#### Success Response
```typescript
interface SuccessResponse {
success: true;
code: 200;
}
```
**Example:**
```json
{
"success": true,
"code": 200
}
```
#### Error Response
```typescript
interface ErrorResponse {
success: false;
code: number; // HTTP error code
message: string; // Error description
}
```
**Example:**
```json
{
"success": false,
"code": 400,
"message": "Invalid signature format"
}
```
### Http Status Codes
| Status Code | Description |
| ----------- | --------------------------------------------- |
| 200 | Success - Transaction save successfully |
| 400 | Bad Request - Invalid parameters or signature |
| 401 | Unauthorized - Invalid or expired signature |
| 403 | Forbidden - Signer is not a multisig member |
| 404 | Not Found - Invalid chain or multisig address |
| 500 | Internal Server Error - Server-side error |