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 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. Once you have that sorted, come back here.
First, make a project folder:
$ mkdir radiator
$ cd radiator
Create a file named Gemfile
containing:
source 'https://rubygems.org'
gem 'radiator'
gem 'highline'
gem 'awesome_print'
Then run the command:
$ bundle install
Create a file named switch_witness.rb
containing:
require 'rubygems'
require 'bundler/setup'
Bundler.require
if ARGV.empty?
puts "Usage: ruby #{__FILE__} "
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:
$ ruby switch_witness.rb gingerninja utopian-io
The above example would remove a vote for gingerninja
and apply a vote for utopian-io
:

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!!