Crust Wiki

Crust Wiki

  • 文档
  • Shadow
  • 贡献
  • Languages icon中文
    • English
    • Help Translate

›基于Algorand构建

概览

  • Crust 概述
  • Crust Grants
  • Crust 生态成长计划
  • CRU 认领
  • 锁定的CRU 认领
  • 锁定的CRU 解锁
  • Bridge

    • Ethereum Bridge
    • Elrond Bridge
  • Crust 钱包
  • Crust 术语
  • CRU18 担保
  • 参数表
  • 贡献

学习

  • 账户
  • Crust 通证
  • 新增绑定
  • 担保人
  • 验证人
  • GPoS
  • sWorker

    • 概览
    • 入网
    • 工作量
  • 去中心化存储市场
  • 存储商户
  • 链上身份
  • 链上治理指南

构建

  • Builder's Portal
  • Crust Storage 101
  • Basics

    • Developer faucet
    • Crust Rocky Network
    • 代码示例:使用Crust存储文件
    • Store file with Crust IPFS Pinning Service API

    Crosschain Storage Solution

    • 基于XCMP的跨链存储解决方案
    • 基于平行链的跨链存储解决方案
    • 基于原生IPFS的跨链存储解决方案
    • 基于智能合约的跨链存储解决方案

    Integration Guide

    • DApp的部署和运行
    • NFT数据存储
    • 内容存储与分发

    Node Guide

    • Crust 节点
    • Crust Storage Manager

    Toolkits

    • Crust Pinner Github Action
    • Crust Pinner NPM Package
    • IPFS W3Auth Gateway
    • IPFS W3Auth Pinning Service

基于EVM构建

  • Overview
  • Build With EVM 101
  • Chains

    • Ethereum
    • Optimism
    • Arbitrum
    • zkSync

    Toolkits

    • SDK

基于Algorand构建

  • Overview
  • Build With Algorand 101
  • Algorand applications

基于TON构建

  • Overview
  • Build With TON 101
  • TON applications

节点

  • 节点概要
  • 节点硬件指南
  • Owner 节点
  • Member 节点
  • Isolation 节点
  • 验证人指南
  • 担保人指南
  • sWorker 版本
  • 节点权益
  • 配置 QoS

存储

  • 概览
  • 存储用户指南
  • 存储商户指南
  • 存储订单清算指南
  • 存储市场权益
  • 使用Crust Apps 存储的问题

Q&A

  • 基础知识
  • 验证人和候选人
  • 担保人
  • 奖励和惩罚
  • 节点基本问题
  • Member节点相关
  • 组相关
  • 修复不稳定链
  • 应用
  • EPID & ECDSA
  • 其它
Translate

Build With Algorand 101

I. Description

This article will describe how to use Algorand storage smart contract(short for storage contract below) to place order.

II. Concepts

IPFS

IPFS(InterPlanetary File System) is a p2p storage procotol, anyone can start an IPFS node to share files or pull files from others' nodes. The file stored in IPFS is divided into many pieces which are organized in the form of merkle tree. The root hash of this tree is the cid(content id) of the file, which represents the file itself. An IPFS node can search its wanted cid in IPFS network, when a node claims it has the cid, they can establish a connection and the file data would be sent to the searcher. For more information about IPFS, check this document.

Crust Network

Crust Network is a decentralized storage platform built on IPFS protocol. It is an incentive layer to encourage storage nodes to store the ordered files. MPOW and GPOS are the core protocols of Crust Network. With these protocols Crust Network builds the DSM(Decentralized Storage Market) to provide storage service for the whole Web3 ecosystem.

III. Storage smart contract

  • Testnet storage contract application ID: 507867511
  • Mainnet storage contract application ID: 1275319623

IV. Example

Before you place order with storage contract, you need uploading your file to an IPFS gateway. You can start a local gateway, or use the public ones, or use these maintained by Crust Network. After that let's rock.

0. Build web3 authentication header with Algorand

import sys
from algosdk import account, mnemonic
from nacl.signing import SigningKey
import base64

# 1. Construct auth header
args = sys.argv[1:]
mn = args[0]
pk = mnemonic.to_private_key(mn)
addr = account.address_from_private_key(pk)
sk = list(base64.b64decode(pk))
sig_hex = f"0x{SigningKey(bytes(sk[:32])).sign(addr.encode()).signature.hex()}"
authHeader = base64.b64encode(f"sub-{addr}:{sig_hex}".encode('utf-8')).decode('utf-8')

1. Upload files to IPFS Gateway

import requests
import json

# IPFS Web3 Authed Gateway address
ipfsGateway = 'https://gw-seattle.crustcloud.io';

# 2. Upload file to IPFS gateway
headers = { "Authorization" : f"Basic {authHeader}" }
files = {'upload_file': open(<file_path>,'rb')}
res = requests.post(f"{ipfsGateway}/api/v0/add", files=files, headers=headers)
res_json = json.loads(res.text)
cid = res_json['Hash']
size = int(res_json['Size'])

You can get full list of ipfsGateway address here.

2. Get price from storage contract

from w3bucket import app
from beaker import client, localnet
from algosdk.v2client import algod

# 3. Get algod application client
app_id = 1275319623
algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
algod_address = "https://mainnet-api.algonode.cloud"
algod_client = algod.AlgodClient(algod_token=algod_token,algod_address=algod_address)
account = localnet.kmd.LocalAccount(address=addr,private_key=pk)
app_client = client.ApplicationClient(
  client=algod_client,
  app=app,
  sender=account.address,
  signer=account.signer,
  app_id=app_id
)

# 4. Get price
is_permanent = True
price = app_client.call(
  "get_price",
  size=size,
  is_permanent=is_permanent
).return_value

You can get the w3bucket file here.

3. Send storage order transaction to storage contract

from beaker import client
from algosdk.encoding import decode_address
from algosdk.transaction import PaymentTxn
from algosdk.atomic_transaction_composer import TransactionWithSigner

# 5. Get order node to place order
order_node_address = app_client.call(
  "get_random_order_node",
  boxes=[(app_client.app_id, "nodes")]
).return_value

# 6. Place order
sp = app_client.get_suggested_params()
sp.flat_fee = True
sp.fee = 2000 * 4
ptxn = PaymentTxn(
  account.address,
  sp,
  app_client.app_addr,
  price,
)
app_client.call(
  "place_order",
  seed=TransactionWithSigner(ptxn, account.signer),
  merchant=order_node_address,
  cid=cid,
  size=size,
  is_permanent=is_permanent,
  boxes=[(app_client.app_id, decode_address(order_node_address)),(app_client.app_id, "nodes")],
)

You can check the source code here.

← 上一篇下一篇 →
  • I. Description
  • II. Concepts
    • IPFS
    • Crust Network
  • III. Storage smart contract
  • IV. Example
    • 0. Build web3 authentication header with Algorand
    • 1. Upload files to IPFS Gateway
    • 2. Get price from storage contract
    • 3. Send storage order transaction to storage contract
Docs
Getting StartedCRU ClaimsWebsite Hosting with CrustNFT Data Storage with Crust
Community
DiscordTwitterTelegram
More
CooperationGitHub
Copyright © 2025 Crust Network