LogoLogo
Github
  • Overview
    • 📄Litepaper
  • GraphLinq Chain
    • Networks
      • Specs
        • Geth Client
        • Clique Consensus
      • GraphLinq Chain (Mainnet)
        • Wallet
          • Add GraphLinq Chain to Metamask
          • Add GraphLinq Chain To Ledger
        • RPC Public Nodes
        • Json-RPC API
        • Libraries
        • Execution Clients
        • Explorer
        • Status
    • GLQ
      • Allocation
      • Bridge
      • Rewards
  • 🎶Run a node
    • Installation
  • Dev tooling
    • Introduction
      • Vision
    • Graphs
      • What are Graphs and how do they work?
      • Creating a graph
      • File compression
      • Graph Cycle Costs
      • Node & Fees
    • Engine
      • Setting up the environment
      • Running an Engine locally
    • Dashboard Interface
      • Importing Graph/Template
      • Deploying a Graph
      • Managing Graph State
    • Blocks
      • Base Variable
        • Boolean
        • Decimal
        • Integer
        • KeyValue
        • Long
        • String
        • Get variable
        • Is Variable Exist
        • Set variable
        • Variable Portal
        • Secret String
      • Common
        • Entry Point
        • On Graph Start
        • Stop Graph
      • Time
        • Get Milliseconds Timestamp
        • Get Milliseconds Timestamp Offset
        • Get Timestamp
        • Get Timestamp Offset
        • Timer
        • Format Date
        • Millisecond Timestamp to Date
        • Timestamp to Date
        • Execution Time Interval
      • JSON
        • Last Node to JSON
        • Convert To JSON
        • Add JSON Property
        • Create JSON Object
        • JSON Deserialize To Array
        • JSON to JSON Object
        • Merge JSON
        • Serialize JSON Object
        • Serialize to JSON
      • Log
        • Print
      • WebSocket
        • WebSocket Client Close
        • WebSocket Client Connector
        • On WebSocket Client Disconnect
        • WebSock Receive Data Event
        • WebSocket Send Data
      • String
        • String Contains
        • Concat String
        • Replace String in String
      • Math
        • Subtract A - B
        • Add A + B
        • Ceiling
        • Divide A / B
        • Floor
        • Modulo A % B
        • Multiply A * B
        • Percentage Difference
        • Round
      • HTTP
        • Array To Body Values
        • Array To JSON Body
        • Put HTTP Request
        • Post HTTP Request
        • Get HTTP Request
        • Delete HTTP Request
      • Function
        • Function Block
        • Add Function Parameter
        • Set Function Result
        • Call Function
        • Get Function Result Parameter
        • Get Function Parameter
      • Transformers
        • String to Base64
      • Data
      • CSV
      • Base Condition
        • Decimal Branch
        • Integer Branch
        • String Branch
        • Boolean Branch
      • Range Condition
        • Decimal Range Branch
      • Array
        • Add Array Element
        • Clear Array
        • Create Array
        • Each Element In Array
        • Get Array Element At Index
        • Get Array Size
        • Keep Last X Elements In Array
      • Dictionary
      • Hosted API
    • Blocks (Messaging)
      • Twitter
      • Twitch
      • Telegram
      • SMTP
      • ShortenURL
      • PushOver
      • PushBullet
      • OpenAI
      • Discord
        • Add Emoji On Message
        • Send Discord Channel File
        • Add Role User
        • On Discord Channel Message
        • On Reaction Added Message
        • On Reaction Removed Message
        • Remove Role User
        • Reply Private Discord Message
        • Send Discord Channel Message
        • Discord Connector
        • On Discord Private Message
    • Blocks (Exchange)
      • Binance
      • Bitfinex
      • Bittrex
      • CoinEx
      • CoinGecko
        • Get CoinGecko Coin
      • Huobi
      • Kraken
      • KuCoin
      • LiveCoinWatch
      • MXC
    • Blocks (Blockchains)
      • Avalanche
        • Network Blocks
          • Avalanche Connector
          • Get Block Parameters
          • Get Transaction Parameters
          • On Avalanche Block
          • On Avalanche Transaction
        • Avascan
          • Get Avascan Supply
          • Get Avascan Global Stats
          • Get Avascan Staking Stats
          • Get Avascan Burned Fees
        • SnowTrace
          • SnowTrace Connector
          • Get ERC-20 Balance For Contract
          • Get ERC-20 Token Supply
          • Get Total AVAX on C-Chain
          • Get AVAX Balance Single Address
      • Binance Smart Chain
        • Network Blocks
          • Binance Smart Chain Connector
          • On Binance Smart Chain Block
          • On Binance Smart Chain Transaction
          • On Binance Smart Chain Wallet Transaction
        • BEP20 Blocks
          • Create BEP20 Token
          • Deploy BEP20 Token
      • Elrond
        • Elrond Connector
        • Get Elrond HyperBlock By Hash
        • Get Elrond Transaction
        • Get Elrond Wallet Balance
      • Ethereum
        • Ethereum Connector
        • On Ethereum Block
        • On Ethereum Transaction
        • On Ethereum Wallet Transaction
        • Estimate Gas Price
        • Get Ether Balance
        • Get Block Parameters
        • Get Transaction Parameters
        • Etherscan
          • Etherscan Connector
          • Etherscan Get Gas Price
        • Ethereum Managed Wallet
          • Get Personal Managed Wallet
        • Ethereum ERC20
          • Get ERC20 Holders
          • Get ERC20 Balance
          • Get ERC20 Information
          • Create ERC20 Token
          • Deploy ERC20 Token
        • Ethereum NFT
          • Create NFT Contract
          • Deploy NFT Contact
          • Create New Mintable NFT Token
          • Deploy New Mintable NFT Token
      • Polygon
        • Polygon Connector
      • Quickswap
        • Get Quickswap Pair Price
        • Get Quickswap Token Price
        • Get Quickswap LP Token
        • Get Quickswap LP Token Price
        • On Quickswap Swap
        • On Quickswap Sync
      • Unicrypt
        • Get Unicrypt Locked Token Parameters
        • Get Unicrypt Locked Tokens
        • Get Unicrypt Total Locked Liquidity
        • Get Unicrypt All LP Locked Tokens Address
        • On Unicrypt Deposit
      • Uniswap
        • Get Uniswap LP Token
        • Get Uniswap LP Token Price
        • Uniswap Get Pair Price
        • Get Uniswap Token Price
        • On Uniswap Swap
        • On Uniswap Sync
      • Solana
    • Blocks (Charting)
      • Generate Time Series One Line Chart
      • Generate Time Series Two Line Chart
    • Blocks (Machine Learning)
      • Spam Detection
      • Sentiment Analysis
    • Node Connector Colors
      • Strings & Variables
      • Execution Logic (Yellow)
      • Integers (orange)
      • Booleans (pink)
    • Block Execution Order
      • Additional Block Execution
    • Block Color
      • Colors & Meaning
    • Block Type Overview
      • Function Type
      • Entry Point Type
      • Event Trigger Type
      • Variable Type
      • Condition Type
      • Connector Type
  • Nocode Users
    • Instant Deploy Wizard
    • GraphLinq Marketplace
  • Twitter
  • Medium
  • Github
  • GraphLinq Explorer
  • Audit Report
Powered by GitBook
On this page
  1. Dev tooling
  2. Blocks
  3. Base Variable

Set variable

PreviousIs Variable ExistNextVariable Portal

Last updated 1 year ago

The block is used to store or update a variable with a specified name and value within the graph's data context. It allows us to save data for later use and update variable values as the graph executes.

Set variable blocks have two inputs: a string for the variable's name, and the data that we want to assign to the variable.

The purpose of Set variable blocks is to store data in variables to be used later in our graph's execution with the help of blocks.

If the variable name that we pass to a Set variable block is the name of a variable that already exists, then it will simply overwrite the value of that existing variable with whatever value we passed into the Set variable block. If, on the other hand, no variable yet exists with the name that we pass to our Set variable block, then it will both declare a new variable by that name, and also initialize its value with whatever value we give to the Set variable block.

In the following example, we are retrieving the price of Bitcoin with a block, and then storing that value in a variable named "currentBitcoinPrice" using a Set variable block:

The above graph is meant to print the 1 minute percentage change in bitcoin price, every minute, for as long as we leave the graph running (we just print here to keep the example simple, but it could easily be linked up to a Telegram or Discord bot, etc).

The implication here is that we would later be accessing the value of "currentBitcoinPrice" using a block. While the above example does illustrate the mechanics of the Set variable block, it is worth noting that, in cases like this, it is often sufficient to simply plug the block directly into whatever block(s) needs its output, with no need for the middle step of first storing the data in a variable using a Set variable block, and then retrieving that data later when it's needed with a block.

Whether it makes more sense to plug data we have accessed or created directly into blocks that use that data, or to first store that data in variables using Set variable blocks to later access and use that data using blocks, is something that must be determined on a case-by-case basis.One of the most common use cases for storing our data in variables is when we want to establish something like a Binance connection or an SMTP connection one time, at the beginning of the graph's execution, to be used and reused later on in the graph's execution:

In the example above, we use a Set variable block to declare a variable called "binanceConnector", and then assign to that variable the value of a Binance Connectorblock that has been set up with our API key and secret. Whenever we need a Binance connector later in our graph (for example to place orders on Binance), we can use this same connector by accessing our "binanceConnector" variable with a block.

The next example is more complicated, but it's noteworthy in that it actually requires use of the Set variable and blocks to achieve its purpose:

The flow of this graph is driven by the Timer block, which fires every 60 seconds, triggering the block. The block passes the current price of Bitcoin to a block, which computes the percentage difference between the current price of Bitcoin and the value of a variable called "priceOneMinAgo". The resulting value is added into a message, which is then logged by a block. Finally, now that we are done calculating and printing our message for this cycle, we use a Set variable block to overwrite the value of "priceOneMineAgo" with the current value of Bitcoin that we retrieved with the block. That way, when the Timer block next fires in 60 seconds, the value of "priceOneMinuteAgo" will indeed be Bitcoin's price from one minute before, since one minute prior it was assigned the then-current price of Bitcoin. This allows us to repeatedly compare the current price of Bitcoin to a snapshot of Bitcoin's price from one minute prior, which would not be possible to achieve without using Set variable and blocks.

Get variable
Get CoinGecko Coin
Get variable
Get variable
Get variable
Get variable
Get CoinGecko Coin
Get CoinGecko Coin
Percentage Difference
Print
Get CoinGecko Coin
Get variable
Set Variable
Get variable
Get CoinGecko Coin