ProgrammaticallyinterfacewithyourBlockchain.infowallet.
ContentsGettingStartedUpgradingAPIDocumentationRPCAPIInstallationTroubleshootingUsageDevelopmentDeploymentGettingStartedTousethisAPI,youwillneedtorunsmalllocalservicewhichberesponsibleformanagingyourBlockchain.infowallet.YourapplicationinteractswiththisservicelocallyviaHTTPAPIcalls.
Startbycompletingthefollowingsteps:
FollowtheinstallationinstructionsStarttheserver:$blockchain-wallet-servicestart--port3000Referencethedocumentationandstartinteractingwithyourwalletprogrammatically!Notethatblockchain-wallet-serviceisdesignedtoberunlocallyonthesamemachineasyourapplicationandthereforewillonlyacceptconnectionsfromlocalhost.Ifyoumodifythisservicetoacceptexternalconnections,besuretoaddtheappropriatefirewallrulestopreventunauthorizeduse.
AnAPIcodeisrequiredforwalletcreationandhigherrequestlimits.Forbasicusage,noAPIcodeisrequired.RequestanAPIcodehere.
UpgradingIfyoualreadyhaveanapplicationthatusesBlockchain.info'sWalletAPI,youwillneedtocompletethestepsintheGettingStartedsectionaboveandthen,inyourapplicationcode,replacecallstoblockchain.info/merchant/...withlocalhost:<port>/merchant/....
APIDocumentationViewtheoriginaldocumentation.
AllendpointspresentintheAPIdocumentationabovearesupportedinBlockchainWalletAPIV2.Thedifferencesbetweentwoare:
The"consolidateaddresses"endpointhasbeenomittedAllendpointscanbecalledwithGETorPOST,andcanonlybeaccessedfromlocalhost.
CreatinganewBlockchainWalletEndpoint:/api/v2/create
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(required)priv-privatekeytoimportintowalletasfirstaddress(optional)label-labeltogivetothefirstaddressgeneratedinthewallet(optional)email-emailtoassociatewiththenewlycreatedwallet(optional)SampleResponse:
{"guid":"05f290be-dbef-4636-a809-868893c51711","address":"13R9dBgKwBP29JKo11zhfi74YuBsMxJ4qY","label":"Mainaddress"}MakePaymentEndpoint:/merchant/:guid/payment
QueryParameters:
to-bitcoinaddresstosendto(required)amount-amountinsatoshitosend(required)password-mainwalletpassword(required)second_password-secondwalletpassword(required,onlyifsecondpasswordisenabled)api_code-blockchain.infowalletapicode(optional)from-bitcoinaddressoraccountindextosendfrom(optional)fee-specifytransactionfeeinsatoshifee_per_byte-specifytransactionfee-per-byteinsatoshiItisrecommendedthattransactionfeesarespecifiedusingthefee_per_byteparameter,whichwillcomputeyourfinalfeebasedonthesizeofthetransaction.Youcanalsosetastaticfeeusingthefeeparameter,butdoingsomayresultinalowfee-per-byte,leadingtolongerconfirmationtimes.
SampleResponse:
{"to":["1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq"],"from":["17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY"],"amounts":[200000],"fee":1000,"txid":"f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c","success":true}SendtoManyEndpoint:/merchant/:guid/sendmany
QueryParameters:
recipients-aURIencodedJSONobject,withbitcoinaddressesaskeysandthesatoshiamountsasvalues(required,seeexamplebelow)password-mainwalletpassword(required)second_password-secondwalletpassword(required,onlyifsecondpasswordisenabled)api_code-blockchain.infowalletapicode(optional)from-bitcoinaddressoraccountindextosendfrom(optional)fee-specifytransactionfeeinsatoshifee_per_byte-specifytransactionfee-per-byteinsatoshiItisrecommendedthattransactionfeesarespecifiedusingthefee_per_byteparameter,whichwillcomputeyourfinalfeebasedonthesizeofthetransaction.Youcanalsosetastaticfeeusingthefeeparameter,butdoingsomayresultinalowfee-per-byte,leadingtolongerconfirmationtimes.
URIEncodingaJSONobjectinJavaScript:
varmyObject={address1:10000,address2:50000};varmyJSONString=JSON.stringify(myObject);//`encodeURIComponent`isaglobalfunctionvarmyURIEncodedJSONString=encodeURIComponent(myJSONString);//use`myURIEncodedJSONString`asthe`recipients`parameterSampleResponse:
{"to":["1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq","18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy"],"from":["17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY"],"amounts":[16000,5400030],"fee":2000,"txid":"f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c","success":true}FetchWalletBalanceEndpoint:/merchant/:guid/balance
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(required)SampleResponse:
{"balance":10000}EnableHDFunctionalityEndpoint:/merchant/:guid/enableHD
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)ThiswillupgradeawallettoanHD(HierarchicalDeterministic)Wallet,whichallowstheuseofaccounts.SeeBIP32formoreinformationonHDwalletsandaccounts.
ListActiveHDAccountsEndpoint:/merchant/:guid/accounts
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)ListHDxPubsEndpoint:/merchant/:guid/accounts/xpubs
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)CreateNewHDAccountEndpoint:/merchant/:guid/accounts/create
QueryParameters:
label-labeltoassigntothenewlycreatedaccount(optional)password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)GetSingleHDAccountEndpoint:/merchant/:guid/accounts/:xpub_or_index
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)GetHDAccountReceivingAddressEndpoint:/merchant/:guid/accounts/:xpub_or_index/receiveAddress
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)CheckHDAccountBalanceEndpoint:/merchant/:guid/accounts/:xpub_or_index/balance
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)ArchiveHDAccountEndpoint:/merchant/:guid/accounts/:xpub_or_index/archive
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)UnarchiveHDAccountEndpoint:/merchant/:guid/accounts/:xpub_or_index/unarchive
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)ListAddresses(deprecated,usetheHDAPIinstead)Endpoint:/merchant/:guid/list
QueryParameters:
password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)SampleResponse:
{"addresses":[{"balance":79434360,"address":"1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq","label":"MyWallet","total_received":453300048335},{"balance":0,"address":"17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY","total_received":0}]}FetchAddressBalance(deprecated,usetheHDAPIinstead)Endpoint:/merchant/:guid/address_balance
QueryParameters:
address-addresstofetchbalancefor(required)password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)Note:unlikethehostedAPI,thereisnooptionofaconfirmationsparameterforspecifyingminimumconfirmations.
SampleResponse:
{"balance":129043,"address":"19r7jAbPDtfTKQ9VJpvDzFFxCjUJFKesVZ","total_received":53645423}GenerateAddress(deprecated,usetheHDAPIinstead)Endpoint:/merchant/:guid/new_address
QueryParameters:
password-mainwalletpassword(required)label-labeltogivetotheaddress(optional)api_code-blockchain.infowalletapicode(optional)SampleResponse:
{"address":"18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy","label":"MyNewAddress"}ArchiveAddress(deprecated,usetheHDAPIinstead)Endpoint:/merchant/:guid/archive_address
QueryParameters:
address-addresstoarchive(required)password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)SampleResponse:
{"archived":"18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy"}UnarchiveAddress(deprecated,usetheHDAPIinstead)Endpoint:/merchant/:guid/unarchive_address
QueryParameters:
address-addresstounarchive(required)password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)SampleResponse:
{"active":"18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy"}RPCBitcoindcompatibleRPCAPI.Fulldocumentationavailablehere.
StartingtheRPCserver:
$blockchain-wallet-servicestart-rpc[options]ViewadditionaloptionsandinstructionsunderUsage.
DifferencesfromserverAPI:
Option-rpcsslisnotsupportedMethodlistsinceblockisnotsupportedParamminConfimationsisnotsupportedformethodslistreceivedbyaccountandlistreceivedbyaddressParamminimumConfirmationsisnotsupportedformethodgetbalanceParamconfirmationsisnotsupportedformethodlistaccountsResponsesrepresentingtransactionshaveadifferentformatInstallationnodejsandnpmarerequiredtoinstallandusethisAPIservice.Installation:
$npminstall-gblockchain-wallet-serviceForthebeststabilityandperformance,makesureyouarealwaysusingthelatestversion.
Tocheckyourversion:
$blockchain-wallet-service-VToupdatetothelatestversion:
$npmupdate-gblockchain-wallet-serviceRequires:
node>=6.0.0npm>=3.0.0Ifyouhaveissueswiththeinstallationprocess,seethetroubleshootingsectionbelow.
TroubleshootingInstallationerrors:
IfyouaregettingEACCESSorpermissions-relatederrors,itmightbenecessarytoruntheinstallasroot,usingthesudocommand.
Ifyouaregettingerrorsconcerningnode-gyporpython,installwithnpminstall--no-optional
Startuperrors:
Ifstartupfailswith/usr/bin/env:node:Nosuchfileordirectory,it'spossiblenodeisnotinstalled,orwasinstalledwithadifferentname(Ubuntu,forexample,installsnodeasnodejs).Ifnodewasinstalledwithadifferentname,createasymlinktoyournodebinary:sudoln-s/usr/bin/nodejs/usr/bin/node,orinstallnodethroughNodeVersionManager.Runtimeerrors:
IfyouareseeingaTypeErrorclaimingthatanobjecthasnomethod'compare',itisbecauseyouareonaversionofNodeolderthan0.12,beforethecomparemethodwasaddedtoBuffers.TryupgradingtoatleastNodeversion0.12.
Ifyouaregettingwalletdecryptionerrorsdespitehavingcorrectcredentials,thenit'spossiblethatyoudonothaveJavainstalled,whichisrequiredbyadependencyofthemy-wallet-v3module.NothavingJavainstalledduringthenpminstallprocesscanresultintheinabilitytodecryptwallets.DownloadtheJDKfromhereforMacorbyrunningapt-getinstalldefault-jdkondebian-basedlinuxsystems.
TimeoutErrors:
Ifyouaregettingatimeoutresponse,additionalauthorizationfromyourblockchainwalletmayberequired.ThiscanoccurwhenusinganunrecognizedbrowserorIPaddress.AnemailauthorizingtheAPIaccessattemptwillbesenttotheregistereduserthatwillrequireactioninordertoauthorizefuturerequests.Ifthissectiondidnothelp,pleaseopenagithubissueorvisitoursupportcenter.
UsageAfterinstallingtheservice,thecommandblockchain-wallet-servicewillbeavailableforuse.
Options-h,--help-outputusageinformation-V,--version-outputtheversionnumber-c,--cwd-usethecurrentdirectoryasthewalletservicemodule(developmentonly)CommandsstartUsage:blockchain-wallet-servicestart[options]
Thiscommandwillstarttheservice,makingBlockchainWalletAPIV2availableonaspecifiedport.
Commandoptions:
-h,--help-outputusageinformation-p,--port-portnumbertoruntheserveron(defaultsto3000)-b,--bind-bindtoaspecificip(defaultsto127.0.0.1,notethatbindingtoanipotherthanthiscanleadtosecurityvulnerabilities)--ssl-key-thepathtoyoursslkey(optional)--ssl-cert-thepathtoyoursslcertificate(optional)Toopentheservicetoallincomingconnections,bindto0.0.0.0.
start-rpcUsage:blockchain-wallet-servicestart-rpc[options]
ThiscommandwillstarttheJSONRPCserver.
Options:
-k,--key-apicodetouseforserverrequests(requiredoption)-p,--rpcport-rpcserverport(default:8000)-b,--bind-bindtoaspecificip(defaultsto127.0.0.1,notethatbindingtoanipotherthanthiscanleadtosecurityvulnerabilities)GetanAPIcodehere.
ExamplesTostarttheWalletAPIserviceonport3000:
$blockchain-wallet-servicestart--port3000DevelopmentClonethisrepoRunyarn--ignore-enginesRunyarnstartDevserverisnowrunningonport3000Ifyouaredevelopingblockchain-wallet-clientalongsidethismodule,itisusefultocreateasymlinktomy-wallet-v3:
$ln-s../path/to/my-wallet-v3node_modules/blockchain-wallet-clientTesting$yarntestConfigurationOptionalparameterscanbeconfiguredina.envfile:
PORT-portnumberforrunningdevserver(default:3000)BIND-ipaddresstobindtheserviceto(default:127.0.0.1)DeploymentIfyouwanttouseblockchain-wallet-serviceinyourUNIXproductionserver,youjusthavetorun:
$nohupblockchain-wallet-servicestart--port3000&
评论