You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向Chainlink DON上传加密密钥时网关URL请求失败问题

问题描述

在RWA项目中使用@chainlink/functions-toolkit将加密密钥上传至Chainlink去中心化预言机网络(DON)网关时,向网关发送请求失败。

终端报错信息

Error encountered when attempting to send request to DON gateway URL #1 of 2
https://01.functions-gateway.testnet.chain.link/: AggregateError
Error encountered when attempting to send request to DON gateway URL #2 of 2
https://02.functions-gateway.testnet.chain.link/: AggregateError
Error: Failed to send request to any of the DON gateway URLs:
["https://01.functions-gateway.testnet.chain.link/","https://02.functions-gateway.testnet.chain.link/"]

密钥上传脚本 - uploadSecrets.js

const {
    SecretsManager,
} = require("@chainlink/functions-toolkit")

const {ethers} = require('ethers');


const uploadSecrets = async () => {
    
   const routerAddress = "0xb83E47C2bC239B3bf370bc41e1459A34b41238D0"  //sepolia
    const donId = "fun-ethereum-sepolia-1"
    const gatewayUrls = [
        "https://01.functions-gateway.testnet.chain.link/",
        "https://02.functions-gateway.testnet.chain.link/",
    ]

    
    const privateKey = process.env.PRIVATE_KEY.replace(/\r/g, "").trim(); 
    if (!privateKey)
        throw new Error(
            "private key not provided - check your environment variables"
        )

    const rpcUrl = process.env.SEPOLIA_RPC_URL

    if (!rpcUrl)
        throw new Error(`rpcUrl not provided  - check your environment variables`)

    const secrets = { alpacaKey: process.env.ALPACA_KEY ?? "", alpacaSecret: process.env.ALPACA_SECRET ?? "" }
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
    const wallet = new ethers.Wallet(privateKey)
    const signer = wallet.connect(provider) 

    
    const secretsManager = new SecretsManager({
        signer: signer,
        functionsRouterAddress: routerAddress,
        donId: donId,
    })
    await secretsManager.initialize()

    
    const encryptedSecretsObj = await secretsManager.encryptSecrets(secrets)
    const slotIdNumber = 0 
    const expirationTimeMinutes = 1440 


    console.log(
        `Upload encrypted secret to gateways ${gatewayUrls}. slotId ${slotIdNumber}. Expiration in minutes: ${expirationTimeMinutes}`
    )
    // Upload secrets
    const uploadResult = await secretsManager.uploadEncryptedSecretsToDON({
        encryptedSecretsHexstring: encryptedSecretsObj.encryptedSecrets,
        gatewayUrls: gatewayUrls,
        slotId: slotIdNumber,
        minutesUntilExpiration: expirationTimeMinutes,
    })

    if (!uploadResult.success)
        throw new Error(`Encrypted secrets not uploaded to ${gatewayUrls}`)

    console.log(
        `\n Secrets uploaded properly to gateways ${gatewayUrls}! Gateways response: `,
        uploadResult
    )

    const donHostedSecretsVersion = parseInt(uploadResult.version)
    console.log(`\n Secrets version: ${donHostedSecretsVersion}`)

}

uploadSecrets().catch((e) => {
    console.error(e)
    process.exit(1)
})

预期控制台输出

Secrets uploaded properly to gateways https://01.functions-gateway.testnet.chain.link/! Gateways response

排查与解决步骤

  1. 检查网关可达性

    • 用curl命令测试网关健康状态,确认网络无限制:
      curl https://01.functions-gateway.testnet.chain.link/health
      
    • 若无法访问,排查防火墙、代理或VPN限制,切换网络环境重试。
  2. 验证环境变量配置

    • 确保PRIVATE_KEY、SEPOLIA_RPC_URL等环境变量无多余空格或换行,可在脚本开头添加打印语句确认:
      console.log("PRIVATE_KEY:", privateKey.slice(0,10) + "...");
      console.log("SEPOLIA_RPC_URL:", rpcUrl);
      
  3. 更新工具包版本

    • 检查@chainlink/functions-toolkit版本,更新至最新稳定版:
      npm install @chainlink/functions-toolkit@latest
      
  4. 捕获详细错误

    • 修改脚本添加错误细节捕获,定位具体问题:
      try {
        const uploadResult = await secretsManager.uploadEncryptedSecretsToDON({
            encryptedSecretsHexstring: encryptedSecretsObj.encryptedSecrets,
            gatewayUrls: gatewayUrls,
            slotId: slotIdNumber,
            minutesUntilExpiration: expirationTimeMinutes,
        })
        // 后续逻辑
      } catch (e) {
        if (e instanceof AggregateError) {
          e.errors.forEach((err, idx) => {
            console.error(`网关 ${gatewayUrls[idx]} 错误详情:`, err);
          });
        }
        throw e;
      }
      
  5. 确认钱包与DON配置

    • 验证钱包地址持有足够Sepolia ETH(签名验证需要有效钱包),核对routerAddress和donId与Sepolia测试网官方配置一致。

内容的提问来源于stack exchange,提问作者DEEPAK AGASHE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 21:13:23