Resumen
Enjin runs two Substrate-based chains: the Enjin Matrix Chain (application layer for NFTs and tokens) and the Enjin Relay Chain (consensus and security). Both use Substrate RPC (not EVM JSON-RPC), so developers need to use Polkadot.js or raw WebSocket/HTTPS calls. This article covers public and private RPC endpoints, chain settings, common RPC methods, and how to choose infrastructure for production dApps.
Enjin RPC Decision Checklist
Before integrating Enjin RPC endpoints, consider these criteria:
| Criterion | What to check | Why it matters |
|---|---|---|
| Chain type | Matrix Chain (application) vs Relay Chain (consensus) | Each chain has separate endpoints and RPC methods. Use Matrix Chain for NFT and token operations. |
| Protocol | Substrate RPC (not EVM) | You cannot use eth_* methods. Use Polkadot.js or raw Substrate JSON-RPC. |
| Data retention | Archive vs full vs pruned | Archive nodes store full history; required for historical queries. |
| Endpoint type | Public vs private vs dedicated | Public endpoints have rate limits; private/dedicated offer higher throughput and reliability. |
| Throughput needs | Requests per second (RPS) | Estimate peak load. Shared plans may throttle; dedicated nodes provide consistent performance. |
| WebSocket support | WSS for real-time subscriptions | Required for event listening (e.g., new blocks, token transfers). |
| Geographic latency | Node location relative to your users | Lower latency improves dApp responsiveness. |
| Provider reputation | Uptime history, support, documentation | Check independent reviews and provider SLAs. |
What Is Enjin RPC?
Enjin is a blockchain ecosystem focused on NFTs and gaming, built on Substrate as a Polkadot parachain. It consists of two chains:
- Enjin Matrix Chain: The application layer where NFTs, tokens, and smart contracts live. Most dApp interactions happen here.
- Enjin Relay Chain: The consensus and security layer, inherited from Polkadot. Developers rarely interact with it directly, but it provides finality and cross-chain communication.
Both chains expose RPC endpoints using the Substrate JSON-RPC protocol. This is different from Ethereum's JSON-RPC: there are no eth_* methods. Instead, you use system_*, chain_*, state_*, and custom pallet methods.
Enjin RPC Endpoints
To interact with the Enjin network, you need an RPC endpoint. Options include:
- Public endpoints: Free but rate-limited, suitable for testing and low-traffic apps.
- Private endpoints: Provided by infrastructure services like OnFinality, offering higher rate limits and dedicated support.
- Dedicated nodes: Full control over a node instance, best for production workloads with high throughput.
Example Endpoints (for illustration)
| Chain | HTTPS | WSS |
|---|---|---|
| Matrix Chain | https://enjin-matrix-rpc.example.com | wss://enjin-matrix-rpc.example.com |
| Relay Chain | https://enjin-relay-rpc.example.com | wss://enjin-relay-rpc.example.com |
Note: Replace with actual endpoints from your provider. OnFinality offers Enjin RPC endpoints as part of its supported networks.
Connecting to Enjin RPC
Using Polkadot.js
Polkadot.js is the standard library for interacting with Substrate-based chains.
const { ApiPromise, WsProvider } = require('@polkadot/api');
async function main() {
const wsProvider = new WsProvider('wss://enjin-matrix-rpc.example.com');
const api = await ApiPromise.create({ provider: wsProvider });
// Get chain info
const chain = await api.rpc.system.chain();
const version = await api.rpc.system.version();
console.log(`Connected to ${chain} v${version}`);
// Get latest block hash
const lastHash = await api.rpc.chain.getBlockHash();
console.log(`Latest block hash: ${lastHash}`);
}
main().catch(console.error);
Using curl (HTTPS)
curl -s -X POST https://enjin-matrix-rpc.example.com \
-H 'Content-Type: application/json' \
-d '{"id":1,"jsonrpc":"2.0","method":"chain_getBlockHash","params":[0]}'
Using WebSocket (raw)
wscat -c wss://enjin-matrix-rpc.example.com
> {"id":1,"jsonrpc":"2.0","method":"chain_getBlockHash","params":[0]}
Common RPC Methods
Enjin exposes standard Substrate RPC methods plus custom pallet methods for NFT operations.
System Methods
system_chain– Returns the chain name.system_version– Returns the node version.system_health– Returns node health (peers, syncing status).
Chain Methods
chain_getBlock– Returns block by hash or number.chain_getBlockHash– Returns block hash by number.chain_getHeader– Returns block header.chain_subscribeNewHeads– Subscribe to new block headers.
State Methods
state_getStorage– Returns storage value for a given key.state_getMetadata– Returns runtime metadata.state_queryStorage– Query storage at a specific block.
NFT Methods (Enjin-specific)
Enjin's Multi-Token standard is built into the runtime. Common operations include:
nft.balanceOf(account, tokenId)– Get token balance.nft.totalSupply(tokenId)– Get total supply.nft.ownerOf(tokenId)– Get token owner.
Note: Exact method names depend on the runtime version. Check the Enjin documentation for the latest pallet details.
Choosing an RPC Provider
When selecting an RPC provider for Enjin, consider:
- Supported chains: Ensure the provider offers both Matrix Chain and Relay Chain endpoints.
- Rate limits: Public endpoints often limit requests per second. For production, use a private or dedicated node.
- WebSocket support: Required for real-time features like event subscriptions.
- Geographic distribution: Providers with multiple regions reduce latency.
- Archive data: If you need historical state, choose an archive node provider.
OnFinality provides Enjin RPC endpoints with flexible plans, including shared and dedicated options. See RPC pricing and supported networks for details.
Common Pitfalls and Troubleshooting
1. Using EVM Methods
Enjin is not EVM-compatible. Calling eth_blockNumber will fail. Always use Substrate methods.
2. Rate Limiting
Public endpoints may throttle high-frequency requests. If you see HTTP 429 errors, upgrade to a private endpoint or implement client-side backoff.
3. WebSocket Disconnections
WebSocket connections can drop due to network issues or server load. Implement reconnection logic in your client.
4. Block Finality
Enjin Relay Chain provides finality after a few blocks. For irreversible transactions, wait for finalization before acting.
5. Data Retention
Full nodes prune historical state. For queries on past blocks, use an archive node or an indexer like the Enjin Platform.
Key Takeaways
- Enjin uses Substrate RPC, not EVM JSON-RPC. Use Polkadot.js or raw Substrate calls.
- Two chains: Matrix Chain (application) and Relay Chain (consensus). Most interactions are with Matrix Chain.
- Public endpoints are fine for development; production apps need private or dedicated infrastructure.
- OnFinality offers Enjin RPC endpoints with shared and dedicated options. Check supported networks for availability.
- Always test with a small workload before scaling.
Frequently Asked Questions
Q: Can I use MetaMask with Enjin? A: No, Enjin is not EVM-compatible. Use Polkadot.js or a Substrate wallet.
Q: What is the difference between Matrix Chain and Relay Chain? A: Matrix Chain handles application logic (NFTs, tokens). Relay Chain provides consensus and security. Most dApps interact with Matrix Chain.
Q: How do I get ENJ tokens for gas? A: ENJ is the native token on the Matrix Chain. You can acquire it from exchanges or faucets (for testnets).
Q: Does Enjin support WebSocket subscriptions? A: Yes, both chains support WSS for real-time updates.
Q: Where can I find the latest Enjin RPC methods?
A: Refer to the Enjin documentation and the runtime metadata via state_getMetadata.