Skip to content

Commit 2c28470

Browse files
MantisCloneCopilot
andauthored
feat: add NEAR docs (#3)
Co-authored-by: Copilot <[email protected]>
1 parent 8d4c346 commit 2c28470

File tree

7 files changed

+290
-2
lines changed

7 files changed

+290
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ignore

api-features/payment-detection.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,4 @@ Requests progress through the following payment states:
154154
>
155155
View all supported networks and currencies
156156
</Card>
157-
</CardGroup>
157+
</CardGroup>

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"group": "🌐 Developer Resources",
128128
"pages": [
129129
"resources/supported-chains-and-currencies",
130+
"resources/near-blockchain",
130131
"resources/token-list",
131132
"resources/community"
132133
]

resources/near-blockchain.mdx

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
title: "NEAR (SDK Only)"
3+
description: "Request Network's support for NEAR including native and fungible token payments"
4+
---
5+
6+
import { CopyButton, ExternalLinkButton } from "/snippets/contract-buttons.jsx"
7+
8+
## Overview
9+
10+
Request Network supports payments on NEAR, a sharded, proof-of-stake blockchain that offers unique capabilities compared to EVM-compatible chains. NEAR's architecture enables more complex smart contract interactions through asynchronous callbacks and cross-contract calls.
11+
12+
<Note>
13+
NEAR support is currently available through the **Request Network SDK only**. The Request Network API does not support NEAR blockchain interactions.
14+
</Note>
15+
16+
## Key Differences from EVM Chains
17+
18+
NEAR has several important architectural differences that affect how payments work:
19+
20+
<CardGroup cols={2}>
21+
<Card title="Asynchronous Callbacks" icon="arrows-rotate">
22+
Unlike EVM chains where transactions are atomic, NEAR supports **asynchronous callbacks** that can span multiple transactions or blocks. This enables more complex payment flows but requires different handling.
23+
</Card>
24+
25+
<Card title="Account-Based System" icon="user">
26+
NEAR uses human-readable account names (like `alice.near`) instead of hex addresses. Smart contracts are deployed to named accounts and can be upgraded by their owners.
27+
</Card>
28+
</CardGroup>
29+
30+
<CardGroup cols={2}>
31+
<Card title="Storage Deposits" icon="database">
32+
To receive NEP-141 fungible tokens, accounts must first register with the token contract and pay a small storage deposit (~0.00125 NEAR) to cover storage costs.
33+
</Card>
34+
35+
<Card title="Gas Model" icon="gas-pump">
36+
NEAR uses a different gas model with TGas (TeraGas) units. Gas costs are predictable and much lower than Ethereum mainnet.
37+
</Card>
38+
</CardGroup>
39+
40+
## Supported Payment Types
41+
42+
### Native NEAR Payments
43+
44+
Direct payments using NEAR's native token through the payment proxy smart contract.
45+
46+
**Features:**
47+
- ✅ Direct NEAR token transfers with payment references
48+
- ✅ Fee collection support
49+
- ✅ Payment detection and indexing
50+
51+
### Fungible Token Payments (NEP-141)
52+
53+
Payments using NEAR's fungible token standard (NEP-141) equivalent to ERC-20 on Ethereum.
54+
55+
**Features:**
56+
- ✅ Support for all NEP-141 compliant tokens
57+
- ✅ Fee collection in the same token
58+
- ✅ Payment detection and indexing
59+
- ⚠️ Requires storage deposit registration
60+
61+
### Native Token Conversion Payments
62+
63+
Payments for requests denominated in one currency (typically fiat like USD) but paid in NEAR native tokens. On-chain oracles provide real-time price feeds to calculate the correct NEAR amount.
64+
65+
**Features:**
66+
- ✅ Conversion payments denominated in USD, settled in NEAR
67+
- ✅ Price conversion at the moment of payment, using onchain price feeds
68+
- ✅ Payment detection and indexing
69+
70+
## Smart Contract Addresses
71+
72+
### Mainnet (near)
73+
74+
| Payment Type | Contract Address | Actions | Description |
75+
|--------------|------------------|---------|-------------|
76+
| **Native NEAR Payments** | `requestnetwork.near` | <div className="flex gap-1"><CopyButton text="requestnetwork.near" /><ExternalLinkButton href="https://nearblocks.io/address/requestnetwork.near" /></div> | Direct NEAR token payments with references |
77+
| **Fungible Token Payments** | `pay.reqnetwork.near` | <div className="flex gap-1"><CopyButton text="pay.reqnetwork.near" /><ExternalLinkButton href="https://nearblocks.io/address/pay.reqnetwork.near" /></div> | NEP-141 token payments with fees |
78+
| **Native Conversion Payments** | `native.conversion.reqnetwork.near` | <div className="flex gap-1"><CopyButton text="native.conversion.reqnetwork.near" /><ExternalLinkButton href="https://nearblocks.io/address/native.conversion.reqnetwork.near" /></div> | Fiat/token to NEAR conversions |
79+
80+
### Testnet (near-testnet)
81+
82+
| Payment Type | Contract Address | Actions | Description |
83+
|--------------|------------------|---------|-------------|
84+
| **Native NEAR Payments** | `dev-1631521265288-35171138540673` | <div className="flex gap-1"><CopyButton text="dev-1631521265288-35171138540673" /><ExternalLinkButton href="https://testnet.nearblocks.io/address/dev-1631521265288-35171138540673" /></div> | Direct NEAR token payments with references |
85+
| **Fungible Token Payments** | `pay.reqnetwork.testnet` | <div className="flex gap-1"><CopyButton text="pay.reqnetwork.testnet" /><ExternalLinkButton href="https://testnet.nearblocks.io/address/pay.reqnetwork.testnet" /></div> | NEP-141 token payments with fees |
86+
| **Native Conversion Payments** | `native.conversion.reqnetwork.testnet` | <div className="flex gap-1"><CopyButton text="native.conversion.reqnetwork.testnet" /><ExternalLinkButton href="https://testnet.nearblocks.io/address/native.conversion.reqnetwork.testnet" /></div> | Fiat/token to NEAR conversions |
87+
88+
## Payment Detection
89+
90+
Payment detection for NEAR transactions is handled through dedicated subgraphs:
91+
92+
- **NEAR Mainnet**: [Request Payments Near Subgraph](https://thegraph.com/explorer/subgraphs/9yEg3h46CZiv4VuSqo1erMMBx5sHxRuW5Ai2V8goSpQL?view=Query&chain=arbitrum-one)
93+
- **NEAR Testnet**: [Request Payments Near Testnet Subgraph](https://thegraph.com/explorer/subgraphs/AusVyfndonsMVFrVzckuENLqx8t6kcXuxn6C6VbSGd7M?view=Query&chain=arbitrum-one)
94+
95+
These subgraphs index payment events and transaction data to enable efficient payment detection and status tracking.
96+
97+
## Technical Considerations
98+
99+
### Asynchronous Callbacks
100+
101+
NEAR's asynchronous architecture means payment transactions may require multiple blockchain interactions:
102+
103+
```javascript
104+
// Example: Fungible token payment flow
105+
1. Call ft_transfer_call on token contract
106+
2. Token contract calls proxy contract
107+
3. Proxy processes payment and logs event
108+
4. Callback confirms or reverts transaction
109+
```
110+
111+
This differs from EVM chains where the entire payment happens in a single atomic transaction.
112+
113+
### Storage Deposits
114+
115+
Before receiving NEP-141 tokens, accounts must register with the token contract:
116+
117+
<Warning>
118+
**Important**: Payment addresses must have sufficient storage deposit registered with the token contract. The SDK automatically checks for this requirement and will throw an error if the recipient is not properly registered.
119+
</Warning>
120+
121+
**Minimum Storage Deposit**: ~0.00125 NEAR per token contract
122+
123+
### Gas Considerations
124+
125+
<Tip>
126+
NEAR uses a TGas (TeraGas) unit system and gas costs are predictable and much lower than Ethereum mainnet, typically costing fractions of a cent in USD terms.
127+
</Tip>
128+
129+
## Integration Guide
130+
131+
### Prerequisites
132+
133+
1. **NEAR Wallet Connection**: Applications need to integrate with NEAR wallet providers
134+
2. **SDK Installation**: Use `@requestnetwork/request-client.js` with NEAR support
135+
3. **Account Registration**: Ensure payment recipients are registered for token contracts
136+
137+
### Basic Payment Flow
138+
139+
```javascript
140+
import { RequestNetwork } from '@requestnetwork/request-client.js';
141+
142+
// Create request for NEAR native payment
143+
const request = await requestNetwork.createRequest({
144+
currency: {
145+
type: 'ETH', // NEAR native uses ETH type
146+
value: 'NEAR',
147+
network: 'near'
148+
},
149+
expectedAmount: '1000000000000000000000000', // 1 NEAR in yoctoNEAR
150+
paymentAddress: 'recipient.near'
151+
});
152+
```
153+
154+
## Limitations
155+
156+
<Warning>
157+
**Current Limitations:**
158+
- NEAR support is SDK-only (not available in Request Network API)
159+
- Crosschain payments to/from NEAR are not supported
160+
- Advanced payment types like batch payments are not implemented
161+
</Warning>
162+
163+
## Developer Resources
164+
165+
- [NEAR Documentation](https://docs.near.org/)
166+
- [NEP-141 Fungible Token Standard](https://nomicon.io/Standards/Tokens/FungibleToken/Core)
167+
- [NEAR Smart Contract Source Code](https://github.com/RequestNetwork/near-contracts)
168+
- [Request Network SDK Documentation](https://docs.request.network/advanced/request-network-sdk)

resources/supported-chains-and-currencies.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ For a complete, machine-readable list of all supported tokens with contract addr
7878
</Card>
7979
</CardGroup>
8080

81+
<Warning>
82+
**NEAR Blockchain Support (SDK Only)**
83+
84+
Request Network also supports the NEAR blockchain, but **only through the Request Network SDK** (not the API). NEAR's unique architecture requires different integration patterns.
85+
86+
[Learn more about NEAR support →](/resources/near-blockchain)
87+
</Warning>
88+
8189
## Currency Categories
8290

8391
### Major Cryptocurrencies

snippets/contract-buttons.jsx

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
export const CopyButton = ({ text, title = "Copy Address" }) => {
2+
const handleCopy = (e) => {
3+
const button = e.currentTarget;
4+
const svg = button.querySelector('svg');
5+
6+
if (!navigator.clipboard || !svg) return;
7+
8+
// Store original SVG
9+
const originalSVG = svg.outerHTML;
10+
11+
// Copy to clipboard
12+
navigator.clipboard.writeText(text).then(() => {
13+
// Show checkmark
14+
svg.outerHTML = `
15+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
16+
<polyline points="20 6 9 17 4 12"></polyline>
17+
</svg>
18+
`;
19+
button.setAttribute('data-copied', 'true');
20+
21+
// Reset after 2 seconds
22+
setTimeout(() => {
23+
const checkmark = button.querySelector('svg');
24+
if (checkmark) {
25+
checkmark.outerHTML = originalSVG;
26+
}
27+
button.removeAttribute('data-copied');
28+
}, 2000);
29+
}).catch(() => {
30+
// Silent fail
31+
});
32+
};
33+
34+
return (
35+
<button
36+
onClick={handleCopy}
37+
title={title}
38+
aria-label={title}
39+
className="inline-flex items-center justify-center w-8 h-8 text-gray-600 dark:text-gray-400 transition-all duration-200 rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none"
40+
style={{
41+
'--primary-color': '#01B089'
42+
}}
43+
>
44+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
45+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
46+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
47+
</svg>
48+
<style jsx>{`
49+
button[data-copied="true"] {
50+
color: #10b981 !important;
51+
}
52+
button:hover {
53+
color: var(--primary-color) !important;
54+
}
55+
button:focus {
56+
color: var(--primary-color) !important;
57+
box-shadow: 0 0 0 2px var(--primary-color) !important;
58+
}
59+
`}</style>
60+
</button>
61+
);
62+
};
63+
64+
export const ExternalLinkButton = ({ href, title = "View on Block Explorer" }) => {
65+
// Validate URL to prevent XSS/open redirects
66+
const isValidUrl = (url) => {
67+
try {
68+
const parsed = new URL(url);
69+
return ['http:', 'https:'].includes(parsed.protocol);
70+
} catch {
71+
return false;
72+
}
73+
};
74+
75+
if (!isValidUrl(href)) {
76+
console.error('Invalid URL provided to ExternalLinkButton:', href);
77+
return null;
78+
}
79+
80+
return (
81+
<a
82+
href={href}
83+
target="_blank"
84+
rel="noopener noreferrer"
85+
title={title}
86+
aria-label={title}
87+
className="inline-flex items-center justify-center w-8 h-8 text-gray-600 dark:text-gray-400 transition-all duration-200 rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none no-underline"
88+
style={{
89+
textDecoration: 'none',
90+
borderBottom: 'none',
91+
'--primary-color': '#01B089'
92+
}}
93+
>
94+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
95+
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path>
96+
<polyline points="15,3 21,3 21,9"></polyline>
97+
<line x1="10" y1="14" x2="21" y2="3"></line>
98+
</svg>
99+
<style jsx>{`
100+
a:hover {
101+
color: var(--primary-color) !important;
102+
}
103+
a:focus {
104+
color: var(--primary-color) !important;
105+
box-shadow: 0 0 0 2px var(--primary-color) !important;
106+
}
107+
`}</style>
108+
</a>
109+
);
110+
};

use-cases/subscriptions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,4 @@ app.post('/webhook/subscription', (req, res) => {
326326
>
327327
Set up your account for subscription billing
328328
</Card>
329-
</CardGroup>
329+
</CardGroup>

0 commit comments

Comments
 (0)