Prerequisites
Before onboarding a machine, you should understand:- DID Documents
- See: DID Document.
Instructions
The JavaScript SDK provides a developer-friendly way to:- Create a DID Document for a machine.
- Define the machine’s cryptographic identity using
EcdsaSecp256k1,Ed25519, orSr25519based on the wallet that will be used to create signatures. - Add service endpoints to link ownership and storage solutions.
- Store and retrieve DID-related information from the peaq blockchain.
1. Installing ethers & peaq js
To get started, install:- ethers - library used for wallet generation and token transfer.
- peaq network sdk - generates DID Documents and offers peaq storage.
2. Creating a Machine Wallet
Each machine onboarded to the peaq network needs its own cryptographic identity, so you create a dedicated wallet that represents it. The wallet lets the machine sign data, authenticate itself, and send transactions. peaq is EVM-compatible, so key management uses the ECDSA (Elliptic Curve Digital Signature Algorithm) scheme and the machine can sign with EVM-standard tools. The example below shows how to generate a new wallet using theethers npm package:
ECDSAKeyring class wraps an EVM-compatible wallet. It exposes the machine’s public address, its private key, and a signMessage method used later for signing and authentication.
3. Token Transfer
A machine pays a fee in the network’s native token for every write it makes on chain: registering its DID, storing data on chain, or calling a smart contract. That fee, called gas, pays for computation and storage and keeps spam off the network. Signing a message is done locally on the device, so it needs no gas. After creating the wallet, transfer a small amount of the native token from your admin wallet to the machine wallet. The machine can then transact on its own. If you have no tokens, use the faucet page. The code below demonstrates how to transfer 1 token from an admin account to the machine’s wallet:4. Creating a Machine DID Document
With a funded wallet in place, register a Decentralized Identifier (DID) Document for the machine. The DID Document is a verifiable structure that ties the machine’s cryptographic keys to a unique identifier, so the machine can authenticate itself and prove ownership of its data. The example below registers a DID on the agung testnet with the peaq JavaScript SDK. The document contains:- Verification Methods - Public keys that let others verify signatures made by the machine.
- Service Endpoints - Metadata such as the machine’s admin wallet address or off-chain services.
Putting it all together
The script below runs the complete onboarding flow against the agung testnet:- Creating a machine wallet.
- Loading an administrator wallet (with native tokens).
- Transferring tokens to the machine wallet.
- Registering a DID Document that represents the machine’s on-chain identity.
Summary
Your machine now has a cryptographic identity (an EVM wallet), native tokens to pay for gas, and a DID Document that serves as its verifiable on-chain identity. It can take part in a DePIN: validating credentials, authenticating data, and running tasks on its own. For production:- Store private keys securely, for example in encrypted storage or a secure enclave.
- Do not hardcode secrets into your codebase.
- Use the peaq mainnet endpoint instead of the agung testnet.

