Skip to main content

Spammer API Methods

The Spammer tool lets you add blocks to the tangle when running GoShimmer. Note: Make sure you enable the spammer plugin before interacting with the API.

The API provides the following functions and endpoints:

Client lib APIs:

/spammer

In order to start the spammer, you need to send GET requests to a /spammer API endpoint with the following parameters:

Parameters

Parametercmd
Required or Optionalrequired
DescriptionAction to perform. One of two possible values: start and stop.
Typestring
Parameterrate
Required or Optionaloptional
DescriptionBlocks per time unit. Only applicable when cmd=start. (default: 1)
Typeint
Parameterunit
Required or Optionaloptional
DescriptionIndicates the unit for the spam rate: block per minute or second. One of two possible values: mpm and mps. (default: mps)
Typestring
Parameterimif (Inter Block Issuing Function)
Required or Optionaloptional
DescriptionParameter indicating time interval between issued blocks. Possible values: poisson, uniform.
Typestring

Description of imif values:

  • poisson - emit blocks modeled with Poisson point process, whose time intervals are exponential variables with mean 1/rate
  • uniform - issues blocks at constant rate

Examples

cURL

curl --location 'http://localhost:8080/spammer?cmd=start&rate=100'
curl --location 'http://localhost:8080/spammer?cmd=start&rate=100&imif=uniform&unit=mpm'
curl --location 'http://localhost:8080/spammer?cmd=stop'

Client lib - ToggleSpammer()

Spammer can be enabled and disabled via ToggleSpammer(enable bool, rate int, imif string) (*jsonmodels.SpammerResponse, error)

res, err := goshimAPI.ToggleSpammer(true, 100, "mps", "uniform")
if err != nil {
// return error
}

// will print the response
fmt.Println(res.Block)

Response examples

{ "block": "started spamming blocks" }

Results

Return fieldTypeDescription
blockstringBlock with resulting block.
errorstringError block. Omitted if success.