create account

How to Switch Witness Votes in Ruby by inertia

View this thread on: hive.blogpeakd.comecency.com
· @inertia · (edited)
$26.02
How to Switch Witness Votes in Ruby
<div class="pull-right">
  <blockquote>
    <img src="https://i.imgur.com/yvrNsIo.png" />
  </blockquote>
</div>

Sometimes I will simultaneously unapprove one witness and approve another in the same transaction.  It's more of an OCD thing than a necessity.  It's slightly more efficient because the two operations happen in the same transaction.  Not only that, but it tells a little story if someone goes and looks.  It says, "I'm removing my vote for your witness and replacing it with this person over here."

---

To use this [Radiator](https://steemit.com/steem/@inertia/radiator-steem-ruby-api-client) script, you'll need to install ruby, which I have documented on more than one occasion.  If you need help, I recommend looking at the other artciles on [/f/ruby](https://chainbb.com/f/ruby).  Once you have that sorted, come back here.

First, make a project folder:

```bash
$ mkdir radiator
$ cd radiator
```

Create a file named `Gemfile` containing:

```ruby
source 'https://rubygems.org'
gem 'radiator'
gem 'highline'
gem 'awesome_print'
```

Then run the command:

```bash
$ bundle install
```

Create a file named `switch_witness.rb` containing:

```ruby
require 'rubygems'
require 'bundler/setup'

Bundler.require

if ARGV.empty?
  puts "Usage: ruby #{__FILE__} <unapprove> <approve>"
  exit
end

unapprove, approve = ARGV
cli = HighLine.new
account_name = cli.ask 'Account: '
wif = cli.ask 'Active WIF: ' { |q| q.echo = '*' }

chain_options = {
  chain: :steem,
  url: 'https://api.steemit.com'
}

begin
  tx = Radiator::Transaction.new(chain_options.merge(wif: wif))
rescue RuntimeError => e
  if e.message == 'Invalid version'
    puts "Invalid WIF."
  else
    puts e.message
  end

  exit
end

unapprove_witness_vote = {
  type: :account_witness_vote,
  account: account_name,
  witness: unapprove,
  approve: false
}

approve_witness_vote = {
  type: :account_witness_vote,
  account: account_name,
  witness: approve,
  approve: true
}

tx.operations << unapprove_witness_vote
tx.operations << approve_witness_vote

response = tx.process(true)

if !!response.error
  error = Radiator::ErrorParser.new(response)
  puts error.error_message
else
  ap response.result
end
```

Then run it:

```bash
$ ruby switch_witness.rb gingerninja utopian-io
```

The above example would remove a vote for `gingerninja` and apply a vote for `utopian-io`:

<center>
  [![](https://i.imgur.com/GZg5TRP.png)](https://steemd.com/tx/9782b50013fe3feb5722cadcb5cc4feccf3ba92e)
</center>

---

By the way, I'm very pleased that the blockchain allows me to unapprove/approve in the same transaction *even though* I have already voted for 30 witnesses.  I half expected this script to fail because the transaction contains an approval vote and I've already approved 30 slots.  But instead, it correctly handles this situation.

To the Steemit, Inc. Blockchain Engineers: Well Done*!!*<div class="chainbb-footer"><hr><em><small><a href="https://chainbb.com/radiator/@inertia/how-to-switch-witness-votes-in-ruby">Originally posted</a> in the <a href="https://chainbb.com/f/ruby">/f/ruby</a> forum on <a href="https://chainbb.com">chainBB.com</a> (<a href="https://chainbb.com/chainbb/@jesta/chainbb-frequently-asked-questions-faq">learn more</a>).</small></em></div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 37 others
👎  ,
properties (23)
authorinertia
permlinkhow-to-switch-witness-votes-in-ruby
categoryradiator
json_metadata"{"app":"chainbb/0.4","namespace":"ruby","format":"markdown+html","tags":["radiator","ruby","steem"," howto","witness-category"]}"
created2018-03-07 03:04:09
last_update2018-03-07 03:47:18
depth0
children16
last_payout2018-03-14 03:04:09
cashout_time1969-12-31 23:59:59
total_payout_value20.464 HBD
curator_payout_value5.553 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,261
author_reputation346,568,901,399,561
root_title"How to Switch Witness Votes in Ruby"
beneficiaries
0.
accountchainbb
weight275
1.
accountinertia
weight225
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,766,220
net_rshares6,879,400,685,339
author_curate_reward""
vote details (103)
@abdurrazzak ·
Hello informer,,, thanks for your kindness information post.
Upvoted
👍  
properties (23)
authorabdurrazzak
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180307t030818947z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-07 03:08:30
last_update2018-03-07 03:08:30
depth1
children0
last_payout2018-03-14 03:08:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length68
author_reputation121,581,509,286
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,766,933
net_rshares520,821,924
author_curate_reward""
vote details (1)
@ashe-oro ·
well done! Thank you for providing Ruby insights. Our team at @steemsmarter is using Ruby as well. Make sure and follow our main dev @thescubageek for more Ruby love. 
properties (22)
authorashe-oro
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180308t132617219z
categoryradiator
json_metadata{"tags":["radiator"],"community":"busy","app":"busy/2.4.0"}
created2018-03-08 13:28:54
last_update2018-03-08 13:28:54
depth1
children0
last_payout2018-03-15 13:28:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length167
author_reputation24,151,212,829,722
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id43,111,117
net_rshares0
@bijoy123 ·
I will try it for sure another friend already told me about it Thanks for sharing anyways,,,,
properties (22)
authorbijoy123
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180310t074037117z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-10 07:40:48
last_update2018-03-10 07:40:48
depth1
children0
last_payout2018-03-17 07:40:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length93
author_reputation-136,147,261,373
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id43,472,045
net_rshares0
@bilal-haider ·
$0.06
@inertia :) you created radiator gem ? for steemit ?
I also wanted to create a ruby gem for steemit :) guess you already done the job. probably i will use yours :) will try it very soon.
👍  ,
properties (23)
authorbilal-haider
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180307t040045789z
categoryradiator
json_metadata{"tags":["radiator"],"users":["inertia"],"app":"steemit/0.1"}
created2018-03-07 04:00:48
last_update2018-03-07 04:00:48
depth1
children2
last_payout2018-03-14 04:00:48
cashout_time1969-12-31 23:59:59
total_payout_value0.048 HBD
curator_payout_value0.012 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length186
author_reputation4,891,139,097,092
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,775,772
net_rshares15,934,045,630
author_curate_reward""
vote details (2)
@thescubageek ·
$0.95
The [Radiator gem](https://github.com/inertia186/radiator) is pretty sweet @bilal-haider I've been using it for another project at @steemsmarter to pull in all kinds of data from the blockchain and it's really well coded and not hard at all to get working.
👍  ,
properties (23)
authorthescubageek
permlinkre-bilal-haider-re-inertia-how-to-switch-witness-votes-in-ruby-20180307t050736774z
categoryradiator
json_metadata{"tags":["radiator"],"users":["bilal-haider","steemsmarter"],"links":["https://github.com/inertia186/radiator"],"app":"steemit/0.1"}
created2018-03-07 05:07:36
last_update2018-03-07 05:07:36
depth2
children1
last_payout2018-03-14 05:07:36
cashout_time1969-12-31 23:59:59
total_payout_value0.714 HBD
curator_payout_value0.232 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length256
author_reputation2,455,841,396,924
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,785,654
net_rshares239,841,152,394
author_curate_reward""
vote details (2)
@bilal-haider ·
$0.14
I will try it for sure :) another friend already told me about it..  .. Thanks for sharing anyways.
👍  
properties (23)
authorbilal-haider
permlinkre-thescubageek-re-bilal-haider-re-inertia-how-to-switch-witness-votes-in-ruby-20180307t080018036z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-07 08:00:18
last_update2018-03-07 08:00:18
depth3
children0
last_payout2018-03-14 08:00:18
cashout_time1969-12-31 23:59:59
total_payout_value0.108 HBD
curator_payout_value0.033 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length99
author_reputation4,891,139,097,092
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,813,742
net_rshares36,396,333,305
author_curate_reward""
vote details (1)
@dailylight ·
I would love to make a animation about this give me your thoughts. I'm THE ONLY one animator on DTUBE please check me out and give your thoughts about creating a animation from this article! Thanks.
properties (22)
authordailylight
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180307t030935326z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-07 03:09:36
last_update2018-03-07 03:09:36
depth1
children0
last_payout2018-03-14 03:09:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length198
author_reputation75,774,748,849
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,767,120
net_rshares0
@davidpm ·
oh nice! I'm gonna have to check that radiator gem out
👍  
properties (23)
authordavidpm
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180307t093018541z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-07 09:30:18
last_update2018-03-07 09:30:18
depth1
children0
last_payout2018-03-14 09:30:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length54
author_reputation138,388,664,591
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,829,442
net_rshares2,314,217,724
author_curate_reward""
vote details (1)
@diya28 ·
can we install it on laptop ?
👍  
properties (23)
authordiya28
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180307t182425652z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-07 18:24:24
last_update2018-03-07 18:24:24
depth1
children0
last_payout2018-03-14 18:24:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length29
author_reputation1,661,130,029,399
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,930,064
net_rshares420,766,859
author_curate_reward""
vote details (1)
@gaintshoulder ·
$0.12
Okay this is programming but I don't know the language, is it python? 
The feature you just explained is wonderful but how did you come about it,  it might help with future developments
👍  ,
properties (23)
authorgaintshoulder
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180307t030730259z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-07 03:07:27
last_update2018-03-07 03:07:27
depth1
children1
last_payout2018-03-14 03:07:27
cashout_time1969-12-31 23:59:59
total_payout_value0.092 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length185
author_reputation709,742,325,817
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,766,745
net_rshares30,420,184,973
author_curate_reward""
vote details (2)
@thescubageek ·
$1.47
The awesome [Radiator gem](https://github.com/inertia186/radiator) @inertia made is written in Ruby, as is the sample code above.
👍  ,
properties (23)
authorthescubageek
permlinkre-gaintshoulder-re-inertia-how-to-switch-witness-votes-in-ruby-20180307t050522426z
categoryradiator
json_metadata{"tags":["radiator"],"users":["inertia"],"links":["https://github.com/inertia186/radiator"],"app":"steemit/0.1"}
created2018-03-07 05:05:21
last_update2018-03-07 05:05:21
depth2
children0
last_payout2018-03-14 05:05:21
cashout_time1969-12-31 23:59:59
total_payout_value1.106 HBD
curator_payout_value0.365 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length129
author_reputation2,455,841,396,924
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,785,297
net_rshares372,665,919,393
author_curate_reward""
vote details (2)
@helo ·
$0.03
Hello @inertia, I have a command suggestion for you.  ;-)  I'm sure my friend @robrigo would not mind, he has moved on and voted for me as witness.

`ruby switch_witness.rb agoric.systems helo`

Have a great day!
👍  
properties (23)
authorhelo
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180313t163357412z
categoryradiator
json_metadata{"tags":["radiator"],"users":["inertia","robrigo"],"app":"steemit/0.1"}
created2018-03-13 16:33:57
last_update2018-03-13 16:33:57
depth1
children0
last_payout2018-03-20 16:33:57
cashout_time1969-12-31 23:59:59
total_payout_value0.027 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length212
author_reputation121,547,934,535,311
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id44,175,769
net_rshares9,279,273,880
author_curate_reward""
vote details (1)
@plumey ·
$0.07
Mate, can I just say, I completely understand the big picture and concept but when it comes to the actual detail - I'm at about 2 fifths of fuck all.  I probably need to study up a bit more on this??
👍  
properties (23)
authorplumey
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180308t143305326z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-08 14:33:09
last_update2018-03-08 14:33:09
depth1
children0
last_payout2018-03-15 14:33:09
cashout_time1969-12-31 23:59:59
total_payout_value0.066 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length199
author_reputation3,831,671,740,295
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id43,122,940
net_rshares17,324,809,622
author_curate_reward""
vote details (1)
@theuxyeti ·
the only thing i understood in the post was that you liked UNO. but for that, you get my upvote. just checking in on you bud :)
👍  
properties (23)
authortheuxyeti
permlinkre-inertia-how-to-switch-witness-votes-in-ruby-20180309t025626091z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-09 02:56:36
last_update2018-03-09 02:56:36
depth1
children2
last_payout2018-03-16 02:56:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length127
author_reputation24,787,240,560,666
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id43,235,010
net_rshares3,366,134,872
author_curate_reward""
vote details (1)
@steemsmarter ·
one of my fav childhood memories. Don't forget to say "uno" :P
properties (22)
authorsteemsmarter
permlinkre-theuxyeti-re-inertia-how-to-switch-witness-votes-in-ruby-20180310t053346962z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-10 05:36:36
last_update2018-03-10 05:36:36
depth2
children1
last_payout2018-03-17 05:36:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length62
author_reputation21,691,252,850,789
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id43,456,793
net_rshares0
@theuxyeti ·
hahah
properties (22)
authortheuxyeti
permlinkre-steemsmarter-re-theuxyeti-re-inertia-how-to-switch-witness-votes-in-ruby-20180310t054816541z
categoryradiator
json_metadata{"tags":["radiator"],"app":"steemit/0.1"}
created2018-03-10 05:48:15
last_update2018-03-10 05:48:15
depth3
children0
last_payout2018-03-17 05:48:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation24,787,240,560,666
root_title"How to Switch Witness Votes in Ruby"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id43,458,175
net_rshares0