Prerequisites
Before onboarding a machine, it is recommended you have an understanding of:- DID Documents
- See: DID Document from the learn section.
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 a unique cryptographic identity. This is achieved by creating a dedicated wallet that represents the machine. The wallet enables the machine to sign data, authenticate itself, and perform transactions securely on the network. Since the peaq network is EVM-compatible, we use the ECDSA (Elliptic Curve Digital Signature Algorithm) scheme for key management. This allows machines to sign messages and execute transactions using EVM-standard tools. The example below shows how to generate a new wallet using theethers npm package:
ECDSAKeyring class abstracts the creation and usage of an EVM-compatible wallet. It provides access to the machine’s public address and private key, and exposes a signMessage method that will be used later for signing operations and authentication.
This is not the only way to onboard machines of the network. Sometimes private keys are not necessary when using Machine Smart Accounts. Learn more about Machine Smart Accounts in the Machine Station Factory section. Coming Soon
3. Token Transfer
In order for a machine to interact with the peaq network, it must be able to execute on-chain transactions — such as registering itself, signing data, or interacting with smart contracts. On EVM-compatible networks like peaq, every write operation to the blockchain requires a fee paid in the network’s native token. This fee, often referred to as gas, compensates the network for computation and storage resources, and helps maintain network integrity by preventing spam or malicious activity. After creating a wallet for your machine, you must transfer a small amount of the native token from your admin wallet to the machine wallet. This enables the machine to independently perform transactions on the blockchain. If you have no tokens please checkout our faucet page to receive funds. The code below demonstrates how to transfer 1 token from an admin account to the machine’s wallet:4. Creating a Machine DID Document
Once a wallet and funding are in place, the next step is to register a Decentralized Identifier (DID) Document for the machine. This DID represents the machine’s on-chain identity on the peaq network. A DID Document serves as a verifiable data structure that links the machine’s cryptographic keys to a unique identifier. It allows machines to authenticate themselves, prove ownership of data, and interact securely within the network. In this example, we use the peaq JavaScript SDK to register a DID for the machine on the agung testnet. The DID Document contains:- Verification Methods - Public keys that allow others to verify signatures made by the machine.
- Service Endpoints - Useful metadata such as the machine’s admin wallet address or off-chain services.
Putting it all together
The code below demonstrates the complete flow for onboarding a machine to the peaq network using the agung testnet. This full example includes:- 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
By running this script, you’ve completed the foundational steps to onboard a machine to the peaq network. Your machine now has a cryptographic identity (via EVM wallet), the necessary native tokens to operate, and a DID Document that serves as its verifiable on-chain identity. This setup allows your machine to participate securely in decentralized physical infrastructure networks (DePINs), enabling services such as credential validation, data authentication, autonomous task execution, and more. For production use, always:- Store private keys securely (e.g., encrypted storage or secure enclaves).
- Avoid hardcoding secrets into codebases.
- Use the peaq mainnet endpoint instead of the agung testnet.

