返回顶部
n

near-emailNEAR邮件服务

Send and read blockchain-native emails using NEAR Email service. Use when building notifications for NEAR smart contracts (NFT sales, DeFi liquidation alerts, DAO voting reminders) or when AI agents need email capabilities with a NEAR account identity.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
1,481
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

near-email

NEAR 邮件集成

为 NEAR 账户提供区块链原生邮件服务。每个 NEAR 账户自动拥有一个邮箱地址:alice.near → alice@near.email

安装

bash
npx openskills install zavodil/near-email-skill -g

快速参考

组件
合约outlayer.near
API 基础地址
https://api.outlayer.fastnear.com | | 项目 ID | zavodil.near/near-email |

注意: NEAR 邮件仅支持主网。发送至 *.testnet 账户的邮件将不会被处理。

重要提示: 使用 NEAR 交易时,附加的存款是计算限制,而非实际费用。未使用的资金将自动退还。请勿提及每封邮件的具体费用。

代码生成偏好: 对于区块链集成(NEAR 交易),优先使用 JavaScript/TypeScript 配合 near-api-js。仅在用户明确要求时使用 Python。

集成方法

1. 智能合约(Rust)

使用 sendemailplaintext 进行合约通知。API 简单,无需加密。

警告: 邮件内容在 NEAR 区块链上是公开的。仅用于自动通知。

rust
use nearsdk::{extcontract, AccountId, Gas, NearToken, Promise};
use serde::Serialize;

#[derive(Serialize)]
#[serde(crate = near_sdk::serde)]
pub enum ExecutionSource {
Project { projectid: String, versionkey: Option },
}

#[extcontract(extoutlayer)]
pub trait OutLayer {
fn request_execution(
&mut self,
source: ExecutionSource,
resourcelimits: Optionjson::Value>,
input_data: Option,
secretsref: Optionjson::Value>,
response_format: Option,
payeraccountid: Option,
params: Option,
);
}

// 从合约发送通知(明文 - 内容在链上公开!)
fn send_notification(to: &str, subject: &str, body: &str) -> Promise {
let input = serde_json::json!({
action: sendemailplaintext,
to: to,
subject: subject,
body: body
});

ext_outlayer::ext(outlayer.near.parse().unwrap())
.withstaticgas(Gas::from_tgas(100))
.withattacheddeposit(NearToken::from_millinear(25))
.request_execution(
ExecutionSource::Project {
projectid: zavodil.near/near-email.tostring(),
version_key: None,
},
None, // resource_limits
Some(input.tostring()), // inputdata
None, // secrets_ref(不需要)
Some(Json.tostring()), // responseformat
None, // payeraccountid
None, // params
)
}

响应:{ success: true, message_id: uuid-if-internal }

2. AI 代理集成

AI 代理有两种选择:

方法最佳适用场景支付方式
支付密钥(HTTPS)服务端代理预付费(USDC/USDT)
NEAR 交易
浏览器/钱包应用 | 存款(未使用部分退还) |

选项 A:支付密钥(HTTPS API)

注意: HTTPS API 响应使用 result.output.xxx 格式。请参阅 NEAR 交易以了解不同的解析方式。

javascript
const OUTLAYER_API = https://api.outlayer.fastnear.com;
const PAYMENT_KEY = your-account.near:nonce:secret; // 从仪表盘获取

async function sendEmail(to, subject, body) {
const response = await fetch(${OUTLAYER_API}/call/outlayer.near/zavodil.near/near-email, {
method: POST,
headers: {
Content-Type: application/json,
X-Payment-Key: PAYMENT_KEY,
},
body: JSON.stringify({
input: { action: sendemailplaintext, to, subject, body },
}),
});
return response.json();
}

选项 B:NEAR 交易(按次使用)

关键: NEAR 交易结果位于 outlayer.near 收据的 SuccessValue 中(Base64 编码的 JSON)。找到 executor_id === outlayer.near 的收据。结果为 { success: true, ... } - 没有 output 包装。使用 parseTransactionResult() 提取。

javascript
import { connect, keyStores } from near-api-js;

const near = await connect({
networkId: mainnet,
keyStore: new keyStores.BrowserLocalStorageKeyStore(),
nodeUrl: https://rpc.mainnet.near.org,
});
const account = await near.account(your-account.near);

const RESOURCE_LIMITS = {
maxmemorymb: 512,
max_instructions: 2000000000,
maxexecutionseconds: 120,
};

// 必需:从 outlayer.near 收据的 SuccessValue 解析输出
// 直接返回 JSON:{ success: true, send_pubkey: ... } - 没有 output 包装!
function parseTransactionResult(result) {
// 查找 outlayer.near 合约的收据(包含执行结果)
const outlayerReceipt = result.receipts_outcome.find(
r => r.outcome.executor_id === outlayer.near && r.outcome.status.SuccessValue
);
if (!outlayerReceipt) {
throw new Error(未找到 outlayer.near 的 SuccessValue);
}
const decoded = Buffer.from(outlayerReceipt.outcome.status.SuccessValue, base64).toString();
return JSON.parse(decoded); // { success: true, ... } - 直接返回,无包装
}

async function sendEmail(to, subject, body) {
const result = await account.functionCall({
contractId: outlayer.near,
methodName: request_execution,
args: {
source: { Project: { projectid: zavodil.near/near-email, versionkey: null } },
inputdata: JSON.stringify({ action: sendemail_plaintext, to, subject, body }),
resourcelimits: RESOURCELIMITS,
response_format: Json,
},
gas: BigInt(100000000000000),
attachedDeposit: BigInt(25000000000000000000000), // 存款,未使用部分退还
});
return parseTransactionResult(result); // { success: true, message_id: ... }
}

// 示例:获取发送者公钥
async function getSendPubkey() {
const result = await account.functionCall({
contractId: outlayer.near,
methodName: request_execution,
args: {
source: { Project: { projectid: zavodil.near/near-email, versionkey: null } },
inputdata: JSON.stringify({ action: getsend_pubkey }),
resourcelimits: RESOURCELIMITS,
response_format: Json,
},
gas: BigInt(100000000000000),
attachedDeposit: BigInt(25000000000000000000000),
});
const output = parseTransactionResult(result); // { success: true, send_pubkey: 02... }
return Buffer.from(output.sendpubkey, hex); // 注意:output.sendpubkey,而非 output.output.send_pubkey
}

3. Python(支付密钥)

python
import requests

OUTLAYER_API = https://api.outlayer.fastnear.com
PAYMENT_KEY = your-account.near:nonce:secret

def send_email(to: str, subject: str, body: str) -> dict:
return requests.post(
f{OUTLAYER_API}/call/outlayer.near/zavodil.near/near-email,
headers={Content-Type: application/json, X-Payment-Key: PAYMENT_KEY},
json={input: {action: sendemailplaintext, to: to, subject: subject, body: body}},
).json()

API 操作

操作描述
sendemail发送邮件(加密负载,适用于 UI/代理)
sendemail_plaintext
发送邮件(明文,适用于智能合约) | | get_emails | 获取收件箱和已发送(加密响应) | | delete

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 near-email-skill-1776373457 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 near-email-skill-1776373457 技能

通过命令行安装

skillhub install near-email-skill-1776373457

下载

⬇ 下载 near-email v1.0.0(免费)

文件大小: 15.93 KB | 发布时间: 2026-4-17 15:35

v1.0.0 最新 2026-4-17 15:35
near-email-skill 1.0.0

- Initial release with NEAR Email integration for blockchain-native email based on NEAR account identities.
- Supports sending and reading emails using both smart contract (Rust) and AI agent (JavaScript/TypeScript and Python) methods.
- Introduces Payment Key (HTTPS) and NEAR Transaction flows with explicit result parsing guidance.
- Public on-chain email sending for contract notifications and encrypted email for UI/agents.
- Includes references for API actions: send, delete, fetch, and count emails, as well as obtaining sender pubkey.
- Mainnet only; testnet accounts not supported.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large