Trying to work on blockchain-wallet ruby api methods as in doc https://github.com/Tolsi/blockchain-wallet-ruby/blob/master/lib/blockchain/wallet.rb where am stuck with passing Json parameters for payment
and sendmany
methods.
recipients = {"1H8fsmAgVhUt567I65hGJPkMbnCCy5": "1000000"}
wallet = Blockchain::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78@#^hChttp://ya.ru@contentpurl", nil)
wallet.sendmany(recipients, from = nil, shared = nil, fee = nil, note = nil)
Got error despite substituting the required, Invalid Recipients JSON. Please make sure it is url encoded and consult the docs. (WebAPI::WebApiException)
How to solve the problem ?
In the Blockchain::Wallet gem code, I found this:
def build_url(operation_name, params)
@url + operation_name + "?" + params.map { |param, value| "#{param}=#{value}" if value }.join("&")
end
I believe the way it's being built, you will need to transform in JSON and also encode your recipients string:
require 'json'
require 'uri'
recipients = {"1H8fsmAgVhUt567I65hGJPkMbnCCy5" => "1000000"}
wallet = Blockchain::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78@#^hChttp://ya.ru@contentpurl", nil)
wallet.sendmany(URI.encode(JSON.generate(recipients)))
The recipient will be "%7B%221H8fsmAgVhUt567I65hGJPkMbnCCy5%22:%221000000%22%7D".
References:
UPDATE : Try remove the URI.encode if this does not work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.