You need to enable JavaScript to run this app. Chainlink是否有可靠方案验证IPFS上哈希对应文件的存在性、大小与格式?
优惠活动
大模型
产品
解决方案
定价
更多

Chainlink是否有可靠方案验证IPFS上哈希对应文件的存在性、大小与格式?

基于Chainlink预言机的IPFS文件元数据链上核验实现

实现核心:借助Chainlink类分布式区块链预言机,通过Solidity智能合约以去中心化方式,完成IPFS存储文件的三类属性检索:

  • 文件是否真实存在
  • 文件总字节大小
  • 文件存储格式

测试用IPFS文件示例

示例图片在IPFS上的访问路径为:https://ipfs.io/ipfs/QmYjh5NsDc6LwU3394NbB42WpQbGVsueVSBmod5WACvpte

代码实现示例

方案1:继承IPFSConsumer基础合约

import "@chainlink/contracts/src/v***/IPFSConsumer.sol";

contract VerifyFile is IPFSConsumer {
    // 待核验IPFS哈希:QmYjh5NsDc6LwU3394NbB42WpQbGVsueVSBmod5WACvpte
    function verify(bytes32 hashIPFS) public returns (bool, uint256, string) {
         bytes32 requestId = IPFSmetadata(hashIPFS);
         // 根据requestId处理预言机回调返回的核验结果
    }
}

方案2:通过IPFSInterface接口调用

import "@chainlink/contracts/src/v***/IPFSInterface.sol";

contract VerifyFile {
    IPFSInterface internal IPFSmetadata;
    
    // 待核验IPFS哈希:QmYjh5NsDc6LwU3394NbB42WpQbGVsueVSBmod5WACvpte
    function verify(bytes32 hashIPFS) public returns (bool, uint256, string) {
         (bool exists, uint256 size, string format) = IPFSmetadata.fromHash(hashIPFS);
         // 组装返回最终核验结果
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.23 05:15:06