• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

saurfang/ipfs-multihash-on-solidity: Example on Solidity and web3.js to store IP ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

saurfang/ipfs-multihash-on-solidity

开源软件地址:

https://github.com/saurfang/ipfs-multihash-on-solidity

开源编程语言:

JavaScript 70.2%

开源软件介绍:

Build Status

IPFS hash (multihash) with Solidity and web3.js

Example of using Solidity and web3.js to store and retrieve IPFS hash and more generally multihash.

IPFS hash is often represented using 46 character long Base58 encoding(e.g. QmahqCsAUAw7zMv6P6Ae8PjCTck7taQA6FgGQLnWdKG7U8). It might be attempting to store IPFS hash using bytes or string which are dynamically sized byte array since it cannot fit in the largest fixed-size byte arrays bytes32.

However this can be both expensive and challenging to use IPFS hashes in arrays. Luckily as one might notice that IPFS hashes commonly start with Qm, they in fact follow the multihash self describing hash format:

 <varint hash function code><varint digest size in bytes><hash function output>

This makes it possible to break down IPFS hash into a struct like so:

  struct Multihash {
    bytes32 digest;
    uint8 hashFunction;
    uint8 size;
  }

This repository gives an end-to-end example on how to store IPFS hash in Solidity as well as how to call the smart contract using web3.js to get and set IPFS hash.

IPFSStorage.sol is a smart contract that stores IPFS hash in a mapping from address key to Multihash struct. Because web3.js ABI doesn't support passing tuple as parameter and return type, additional care is taken to normalize the function interface to be web3.js friendly.

multihash.js contains the Javascript code that converts base58 encoded multihash string to and from smart contract friendly arguments and responses.

Refer to test cases for additional example code how to interact with the contract.

Reference

Multihash Format: https://github.com/multiformats/multihash

zeppelin-solidity for project setup and test helpers.

Previous discussions and examples:

How to store IPFS hash using bytes?

A practical guide to cheap IPFS hash storage in an Ethereum smart contract

OriginProtocol Demo Code




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap