Set

Set on Ethereum Virtual Machine

Ethereum
Ethereum
Base
Base

Acts onchain

Ready to run on Base

Assigns a value to a named variable that later steps reference. The value is echoed into a slot bound to the name. Reassignment is by reference, never by name: coil the earlier variable's name input into this action's name slot to write the same slot, so a variable initialized before an if/else and reassigned in each branch carries the branch's value forward. Two Sets that merely type the same name literal are two independent slots; the name is a label, not an identity. Reach for it to give a computed amount or address a stable handle, or to merge results from divergent branches into one value the rest of the plug consumes.

Plug lets you combine onchain actions like this one into a single transaction, without writing a smart contract. Use in App opens a new plug with this action already in it.

Raw Weights to Percents

plug
evm
boolean
18actions
  1. 1·Take

    A caller parameter named count is declared here, its value supplied at execution time to bound both loops below.

  2. 2·Set

    Seeding the accumulator, total is set to 0 before any weight is summed.

  3. 3·Set

    Setting index to 0 establishes the counter for the first pass over the weight slots.

  4. 4·Predicate

    A loop opens that runs while index stays less than count, iterating once per weight slot.

  5. 5·Read map value

    Inside the loop, the weights map in socket storage is read at the current index, returning the raw weight stored at that position.

  6. 6·Calculate

    Arithmetic adds that read weight to the running total.

  7. 7·Set

    Reassigning total to that sum folds this slot's weight into the accumulator.

  8. 8·Calculate

    Advancing the counter, index is added to 1.

  9. 9·Set

    The incremented result is written back into index for the next pass.

  10. 10·End block

    Closing the loop block returns control to the condition until index reaches count.

  11. 11·Set

    Resetting index to 0 restarts the counter for the second pass.

  12. 12·Predicate

    A loop opens again while index stays less than count, iterating once per slot to rewrite each weight.

  13. 13·Read map value

    Inside this pass, the weights map is read at the current index, returning that slot's raw weight.

  14. 14·Multiply then divide

    Multiplying the raw weight by 100 then dividing by total, rounding down, converts it into a percentage of the summed total.

  15. 15·Set map value

    Writing that percentage back into the weights map at index in socket storage overwrites the raw weight with its percent share.

  16. 16·Calculate

    Bumping the counter, index is added to 1.

  17. 17·Set

    That incremented result is written back into index for the next pass.

  18. 18·End block

    Closing the loop block completes the second pass over the weight set.

Take
Set to
Set to
Read map value of in in
Calculate
Set to
Calculate
Set to
End block
Set to
Read map value of in in
Calculate times divided by rounded
Set map value of in in to
Calculate
Set to
End block

More plugs on Base

Borrow on Base · 7 plugs

Stake on Base · 9 plugs

Provide liquidity on Base · 6 plugs

Posts · 11

More on Ethereum Virtual Machine · 11

On other protocols · 1