GithubHelp home page GithubHelp logo

meong1234 / mam.client.go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from habpygo/zero-value-msg.client.go

0.0 2.0 0.0 14 KB

Masked Authenticated Messages IOTA client written in Golang

Go 100.00%

mam.client.go's Introduction

mamgoiota

Small project to implement Masked Authenticated Messaging on the IOTA tangle with Golang.

This project is still under construction (see TODO) with the aim to get IoT sensors and devices to send MAMs.

Install

It is assumed that you have Golang installed. You also need to install the Go library API for IOTA which you can download at:

go get -u github.com/iotaledger/giota

After that you can download the mamgoiota package.

go get -u github.com/habpygo/mam.client.go

To be able to do testing and assertions you have to install the stretchr package

go get -u github.com/stretchr/testify

Sending MAMs to the IOTA tangle with Go

API

Create a new Connection

import gmam "github.com/habpygo/mam.client.go"

func main(){
    c, err := gmam.NewConnection("someNodeURL", "yourSeed")
    if c != nil && err == nil{
        fmt.Println("Connection is valid")
    }
}

If you don't have a nodeURL try out one from: http://iotasupport.com/lightwallet.shtml

If you don't have a seed yet, follow the description here: https://iota.readme.io/docs/securely-generating-a-seed

Please keep in mind that you may NEVER loose this seed nor give it to anybody else, because the seed is the connection to your funds!

WARNING: Nodes have a nasty habit to go on/off line without warning or notice. If this happens try to find another one.

Send a MAM to the IOTA tangle

import gmam "github.com/habpygo/mam.client.go"

func main(){
    c, err := gmam.NewConnection("someNodeURL", "yourSeed")
    if err != nil{
        panic(err)
    }
    id, err := gmam.Send("the receiving address", 0, "your stringified message", c)
    if err != nil{
        panic(err)
    }
    fmt.Printf("Send to the Tangle. TransactionId: %v\n", id)
}

After sending, you find your transaction here https://thetangle.org giving the TransactionId

If you want to transfer value aswell (here 100 IOTA) call the send method like this: Send("the receiving address", 100, "your stringified message", c).

Read data from the IOTA tangle

Reading all transaction received by a certain adress:

import gmam "github.com/habpygo/mam.client.go"

func main(){
    c, err := gmam.NewConnection("someNodeURL", "")
    if err != nil{
        panic(err)
    }

    ts, err := gmam.ReadTransactions("Receiving Address", c)
    if err != nil{
        panic(err)
    }
    for i, tr := range ts {
        t.Logf("%d. %v: %d IOTA, %v to %v\n", i+1, tr.Timestamp, tr.Value, tr.Message, tr.Recipient)
    }
}

The seed can be ommitted here, since reading does not require an account

Reading a special transaction by transactionID:

import gmam "github.com/habpygo/mam.client.go"

func main(){
    c, err := gmam.NewConnection("someNodeURL", "")
    if err != nil{
        panic(err)
    }

    tx, err := gmam.ReadTransaction("Some transactionID", c)
    if err != nil{
        panic(err)
    }
    t.Logf("%v: %d IOTA, %v to %v\n", tx.Timestamp, tx.Value, tx.Message, tx.Recipient)
}

Examples

Check out our example folder for a send and a receive example.

To run this, cd into the example folder and edit the sender/send.go and receiver/receive.go file, set the correct provider and address and you are ready to run.

Start the receiver first: $ go run receiver/receive.go. It will check for new messages every 5 seconds, until cancelled.

Then start the sender: $ go run sender/send.go.

You can also read all the past transactions, i.e. messages + value, at the address: go run history/history.go.

If you pick up the transaction hash from the Terminal output and paste it into the input field on the site https://thetangle.org you find your transaction.

If the Node is offline try another one, mentioned above.

TODOs

  • GoDoc
  • Travis
  • Make web-app
  • Read sensor data, e.g. RuuVi tag
  • More Read options
  • Read by TransactionId

mam.client.go's People

Contributors

jpolack avatar habpygo avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.