Skip to main content

Communication Layer APIs

The communication layer represents the base Tangle layer where so called Blocks are gossiped around. A Block contains payloads and it is up to upper layers to interpret and derive functionality out of them.

The API provides the following functions to interact with this primitive layer:

Client lib APIs:

/blocks/:blockID

Return block from the tangle.

Parameters

ParameterblockID
Required or Optionalrequired
DescriptionID of a block to retrieve
Typestring

Examples

cURL

curl --location --request GET 'http://localhost:8080/blocks/:blockID'

where :blockID is the base58 encoded block ID, e.g. 4MSkwAPzGwnjCJmTfbpW4z4GRC7HZHZNS33c2JikKXJc.

Client lib - GetBlock

Blocks can be retrieved via GetBlock(base58EncodedID string) (*jsonmodels.Block, error)

block, err := goshimAPI.GetBlock(base58EncodedBlockID)
if err != nil {
// return error
}

// will print "Hello GoShimmer World"
fmt.Println(string(block.Payload))

Note that we're getting actual Block objects from this call which represent a vertex in the communication layer Tangle. It does not matter what type of payload the block contains, meaning that this will also return blocks which contain a transactions or DRNG payloads.

Response Examples

{
"id": "4MSkwAPzGwnjCJmTfbpW4z4GRC7HZHZNS33c2JikKXJc",
"strongParents": [
"6LrXyDCorw8bTWKFaEmm3CZG6Nb6Ga8Bmosi1GPypGc1",
"B89koPthm9zDx1p1fbkHwoyC1Buq896Spu3Mx1SmSete"
],
"weakParents": [],
"strongChildren": [
"4E4ucAA9UTTd1UC6ri4GYaS4dpzEnHPjs5gMEYhpUK8p",
"669BRH69afQ7VfZGmNTMTeh2wnwXGKdBxtUCcRQ9CPzq"
],
"weakChildren": [],
"issuerPublicKey": "9DB3j9cWYSuEEtkvanrzqkzCQMdH1FGv3TawJdVbDxkd",
"issuingTime": 1621873309,
"sequenceNumber": 4354,
"payloadType": "GenericDataPayloadType(0)",
"payload": "BAAAAAAAAAA=",
"signature": "2J5XuVnmaHo54WipirWo7drJeXG3iRsnLYfzaPPuy6TXKiVBqv6ZYg2NjYP75xvgvut1SKNm8oYTchGi5t2SjyWJ"
}

Results

Return fieldTypeDescription
idstringBlock ID.
strongParents[]stringList of strong parents' block IDs.
weakParents[]stringList of weak parents' block IDs.
strongChildren[]stringList of strong children' block IDs.
weakChildren[]stringList of weak children' block IDs.
issuerPublicKey[]stringPublic key of issuing node.
issuingTimeint64Time this block was issued
sequenceNumberuint64Block sequence number.
payloadTypestringPayload type.
payload[]byteThe contents of the block.
signaturestringBlock signature.
errorstringError block. Omitted if success.

/blocks/:blockID/metadata

Return block metadata.

Parameters

ParameterblockID
Required or Optionalrequired
DescriptionID of a block to retrieve
Typestring

Examples

cURL

curl --location --request GET 'http://localhost:8080/blocks/:blockID/metadata'

where :blockID is the base58 encoded block ID, e.g. 4MSkwAPzGwnjCJmTfbpW4z4GRC7HZHZNS33c2JikKXJc.

Client lib - GetBlockMetadata

Block metadata can be retrieved via GetBlockMetadata(base58EncodedID string) (*jsonmodels.BlockMetadata, error)

block, err := goshimAPI.GetBlockMetadata(base58EncodedBlockID)
if err != nil {
// return error
}

// will print whether block is finalized
fmt.Println(string(block.Finalized))

Response Examples

{
"id": "4MSkwAPzGwnjCJmTfbpW4z4GRC7HZHZNS33c2JikKXJc",
"receivedTime": 1621873309,
"solid": true,
"solidificationTime": 1621873309,
"structureDetails": {
"rank": 23323,
"pastMarkerGap": 0,
"isPastMarker": true,
"pastMarkers": {
"markers": {
"1": 21904
},
"highestIndex": 21904,
"lowestIndex": 21904
}
},
"conflictID": "ConflictID(MasterConflictID)",
"scheduled": false,
"booked": true,
"invalid": false,
"confirmationState": 3,
"confirmationStateTime": 1621873310
}

Results

Return fieldTypeDescription
idstringBlock ID.
receivedTimeint64Time when block was received by the node.
solidboolFlag indicating whether the block is solid.
solidificationTimeint64Time when block was solidified by the node.
structureDetailsStructureDetailsList of weak children' block IDs.
conflictIDstringName of conflict that the block is part of.
scheduledboolFlag indicating whether the block is scheduled.
bookedboolFlag indicating whether the block is booked.
eligibleboolFlag indicating whether the block is eligible.
invalidboolFlag indicating whether the block is invalid.
finalizedboolFlag indicating whether the block is finalized.
finalizedTimestringTime when block was finalized.
errorstringError block. Omitted if success.

/data

Method: POST

A data block is simply a Block containing some raw data (literally bytes). This type of block has therefore no real functionality other than that it is retrievable via GetBlock.

Parameters

Parameterdata
Required or Optionalrequired
Descriptiondata bytes
Typebase64 serialized bytes

Body

{
"data": "dataBytes"
}

Examples

cURL

curl --location --request POST 'http://localhost:8080/data' \
--header 'Content-Type: application/json' \
--data-raw '{"data": "dataBytes"}'

Client lib - Data

Data(data []byte) (string, error)
blockID, err := goshimAPI.Data([]byte("Hello GoShimmer World"))
if err != nil {
// return error
}

Note that there is no need to do any additional work, since things like tip-selection, PoW and other tasks are done by the node itself.

Response Examples

{
"id": "blockID"
}

Results

Return fieldTypeDescription
idstringBlock ID of the block. Omitted if error.
errorstringError block. Omitted if success.

/blocks/payload

Method: POST

SendPayload() takes a payload object of any type (data, transaction, drng, etc.) as a byte slice, issues a block with the given payload and returns its blockID. Note that the payload must be valid, otherwise an error is returned.

Parameters

Parameterpayload
Required or Optionalrequired
Descriptionpayload bytes
Typebase64 serialized bytes

Body

{
"payload": "payloadBytes"
}

Examples

cURL

curl --location --request POST 'http://localhost:8080/blocks/payload' \
--header 'Content-Type: application/json' \
--data-raw '{"payload": "payloadBytes"}'

Client lib - SendPayload

SendPayload(payload []byte) (string, error)
helloPayload := payload.NewData([]byte{"Hello GoShimmer World!"})
blockID, err := goshimAPI.SendPayload(helloPayload.Bytes())

Response Examples

{
"id": "blockID"
}

Results

Return fieldTypeDescription
idstringBlock ID of the block. Omitted if error.
errorstringError block. Omitted if success.

Note that there is no need to do any additional work, since things like tip-selection, PoW and other tasks are done by the node itself.