go get -d github.com/ethereum/go-ethereum
go install github.com/ethereum/go-ethereum/cmd/geth
go install github.com/ethereum/go-ethereum/cmd/swarm
geth account new
export BZZKEY=970ef9790b54425bea2c02e25cab01e48cf92573
swarm --bzzaccount $BZZKEY
Last active
November 5, 2018 07:42
-
-
Save qbig/7e5eda601c528f09c432a68f9b4ee238 to your computer and use it in GitHub Desktop.
Swarm: Swarm in Ethereum's decentralized and distributed storage solution, comparable to IPFS.
geth account new
export BZZKEY=970ef9790b54425bea2c02e25cab01e48cf92573
swarm --bzzaccount $BZZKEY
swarm_download.go
package main
import (
"fmt"
"io/ioutil"
"log"
bzzclient "github.com/ethereum/go-ethereum/swarm/api/client"
)
func main() {
client := bzzclient.NewClient("http://127.0.0.1:8500")
manifestHash := "2e0849490b62e706a5f1cb8e7219db7b01677f2a859bac4b5f522afd2a5f02c0"
manifest, isEncrypted, err := client.DownloadManifest(manifestHash)
if err != nil {
log.Fatal(err)
}
fmt.Println(isEncrypted) // false
for _, entry := range manifest.Entries {
fmt.Println(entry.Hash) // 42179060941352ba7b400b16c40f1e1290423a826de2a70587034dc14bc4ab2f
fmt.Println(entry.ContentType) // text/plain; charset=utf-8
fmt.Println(entry.Size) // 12
fmt.Println(entry.Path) // ""
}
file, err := client.Download(manifestHash, "")
if err != nil {
log.Fatal(err)
}
content, err := ioutil.ReadAll(file)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(content)) // hello world
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
bzzclient "github.com/ethereum/go-ethereum/swarm/api/client" | |
) | |
func main() { | |
client := bzzclient.NewClient("http://127.0.0.1:8500") | |
file, err := bzzclient.Open("hello.txt") | |
if err != nil { | |
log.Fatal(err) | |
} | |
manifestHash, err := client.Upload(file, "", false) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(manifestHash) // 2e0849490b62e706a5f1cb8e7219db7b01677f2a859bac4b5f522afd2a5f02c0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment