diff --git a/README.md b/README.md index a7621a8..0a3e8a5 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,58 @@ + + # go-cardano-serialization -Golang library for serialization & deserialization of Cardano data structures. + +

Golang library for serialization & deserialization of Cardano data structures. +
+ +

+ Quickstart • + Examples • + Testing +

+
## Quickstart Make sure you are using Go 1.15+, and Go modules support is enabled. - Install or update `go-cardano-serialization` package commands with: - ``` - go get github.com/fivebinaries/go-cardano-serialization - ``` + +Install or update `go-cardano-serialization` package commands with: + +```console +$ go get github.com/fivebinaries/go-cardano-serialization +``` + +## Examples + +An example of Cardano addresses serialization in Go. + +```go +// load address from Base58 +addr, err := FromBytes(base58.Decode("Ae2tdPwUPEZ4YjgvykNpoFeYUxoyhNj2kg8KfKWN2FizsSpLUPv68MpTVDo")) +if err != nil { + log.Panic(err) +} +// get ByronAddress +byronAddr := addr.ToByronAddress() +// get protocol magic for Byron address +magic := byronAddr.ProtocolMagic() +// get network ID for Byron address +netId := byronAddr.NetworkId() +// create new base address +keyBytes := [crypto.Ed25519KeyHashLen]byte{} +scriptBytes := [crypto.ScriptHashLen]byte{} +for i := range keyBytes { + keyBytes[i] = 23 +} +for i := range scriptBytes { + scriptBytes[i] = 42 +} +addrBase := NewBaseAddress(5, StakeCredetialFromKeyHash(keyBytes[:]), StakeCredetialFromScriptHash(scriptBytes[:])) +addrBytes := addrBase.ToBytes() +``` -Address API example: - ```go - // load address from Base58 - addr, err := FromBytes(base58.Decode("Ae2tdPwUPEZ4YjgvykNpoFeYUxoyhNj2kg8KfKWN2FizsSpLUPv68MpTVDo")) - if err != nil { - log.Panic(err) - } - // get ByronAddress - byronAddr := addr.ToByronAddress() - // get protocol magic for Byron address - magic := byronAddr.ProtocolMagic() - // get network ID for Byron address - netId := byronAddr.NetworkId() - // create new base address - keyBytes := [crypto.Ed25519KeyHashLen]byte{} - scriptBytes := [crypto.ScriptHashLen]byte{} - for i := range keyBytes { - keyBytes[i] = 23 - } - for i := range scriptBytes { - scriptBytes[i] = 42 - } - addrBase := NewBaseAddress(5, StakeCredetialFromKeyHash(keyBytes[:]), StakeCredetialFromScriptHash(scriptBytes[:])) - addrBytes := addrBase.ToBytes() - ``` ## Tests You can run all tests with the command: - ```go - go test ./... - ``` \ No newline at end of file + +```console +$ go test ./... +```