Documentation
  • PROTOCOL
    • About
    • Glossary
    • Protocol Roles
      • Creators
        • Creator NFT (mNFT)
      • Players
      • Analysts
        • Analyst NFT (vNFT)
      • Dispute Resolution
        • High Guard
    • FORE Markets
      • Market Types
      • Payout Logic
      • Protocol Rewards
    • Market Phases
      • Creation Phase
      • Participation Phase
      • Validation Phase
      • Dispute Phase
      • Resolution Phase
    • Protocol Rewards
      • Player Rewards
      • Infrastructure Rewards
      • NFT Tiers
    • NFT Marketplace
    • Config
      • Protocol Config
      • Market Config
  • DEVELOPERS
    • Addresses and Config
    • Smart Contracts
      • ForeMarkets (Factory)
      • ForeMarket
      • ProtocolConfig
      • MarketConfig
      • ForeAnalysts
      • ForeToken
    • IPFS
      • Verifier NFT Metadata Format
      • Market NFT Metadata Format
      • Market Object Format
      • Base58 <->Bytes32
Powered by GitBook
On this page
  1. DEVELOPERS
  2. IPFS

Base58 <->Bytes32

Storing a string in solidity is quite expensive. So we use the string hash(base58) to bytes32 conversion function. And we store the data as bytes32.

Below are the implementations of the convert function in two directions.

import bs58 from 'bs58'

getBytes32FromIpfsHash(ipfsListing) {
  return "0x"+bs58.decode(ipfsListing).slice(2).toString('hex')
}

getIpfsHashFromBytes32(bytes32Hex) {
  const hashHex = "1220" + bytes32Hex.slice(2)
  const hashBytes = Buffer.from(hashHex, 'hex');
  const hashStr = bs58.encode(hashBytes)
  return hashStr
}
PreviousMarket Object Format

Last updated 2 years ago