Skip to content

Instantly share code, notes, and snippets.

Created March 26, 2022 09:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?

Claim Reddish Pixels

This is an example on how to programatically claim pixels on the redish pixel game canvas by sending messages to the HCS (Hedera Consensus Services). Please be aware that dedicated canvases without user cooldown exist for botting.


  • NodeJs
  • A Hedera account with at least 0.0001$ of Hbar

Run the following commands to get started

# create directory
mkdir CanvasAutomation
cd CanvasAutomation

# Setup project files 
npm init -y
# Install dependencies
npm i @hashgraph/sdk dotenv typescript

# Create necessary empty files 
touch .env
touch index.ts

# Setup typescript
tsc --init

Copy the content of index.ts and env into the correct files and replace the missing values with your desired input.

You will need to provide:

  • your hedera account id
  • your private key
  • the hcs topic id of the game you want to interact with (additionally location, description and color)

Save the files and convert the .ts file into javascript which can be executed by the node runtime


An index.js file should now appear alongside the index.ts file. (You can also run tsc --watch) and the index.js file will automatically be regenerated each time you make changes to the typescript file.

node ./index.js
import { AccountId, PrivateKey, Client, TopicMessageSubmitTransaction, Status } from '@hashgraph/sdk';
import { config } from 'dotenv';
* Import personal credentials. You can skip this and hardcode your values.
* But getting used to do it properly can't hurt.
if (process.env.HEDERA_ACCOUNT_ID === undefined) {
throw new Error('Hedera Account Id not specified in env file');
if (process.env.HEDERA_PRIVATE_KEY === undefined) {
throw new Error('Hedera Private Key not specified in env file');
const ACCOUNT_ID = AccountId.fromString(process.env.HEDERA_ACCOUNT_ID);
const ACCOUNT_KEY = PrivateKey.fromString(process.env.HEDERA_PRIVATE_KEY);
* Specify which pixel you want to claim and how to set its value
// The HCS topic id can be found in the /pixels overview page or copied from the url /pixel/0.0.XXXXXXX
// Which pixel do you want to claim? [0-size-1]
const pixelX = 0;
const pixelY = 0;
const color = '#00bced';
const description = 'My first pixel claimed via a script';
* Setup entry point with the hedera network
const client = process.env.NODE_ENV === 'development' ? Client.forTestnet() : Client.forMainnet();
client.setOperator(ACCOUNT_ID, ACCOUNT_KEY);
* Send a message to the HCS service and set a pixel on the specified canvas to the supplied color.
* @param x the pixels x position on the canvas
* @param y the pixels y position on the canvas
* @param hexColor hex 6 color value of the pixel
* @param description arbitrary text message displayed when looking at the pixel via the homepage
const claimPixel = async (x: number, y: number, hexColor: string, description: string) => {
//Descriptions are truncated after 240 characters on the homepage. You can choose to send a longer message but this only means increased transaction fees.
const descriptionEscaped = description.trim().substring(0, 240);
//Construct payload. This format is specified in the docs found on the homepage.
const payload = `${hexColor}|${x}|${y}|${descriptionEscaped}`;
const submitTx = new TopicMessageSubmitTransaction({
message: payload,
const txSubmitted = await submitTx.execute(client);
const txReceipt = await txSubmitted.getReceipt(client);
if (txReceipt.status != Status.Success) {
console.log('Message could not be sent correctly: ' + txReceipt.status);
} else {
console.log('Message submitted to the network. The update should be visible after 4 - 5 seconds');
// Finally claim your pixel.
* Here you can run a loop.
* Be aware that we are publishing a transaction to the DLT which incurs a fee.
* Additionally you should spread your load across multiple hcs nodes or introduce
* a small delay or else your traffic might be dropped.
claimPixel(pixelX, pixelY, color, description);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment