service-my-wallet-v3 Blockchain Wallet API Service

我要开发同款
匿名用户2021年12月24日
36阅读
开发技术Python
所属分类Web3、开源货币/比特币
授权协议AGPL-3.0 License

作品详情

BlockchainWalletAPIV2

ProgrammaticallyinterfacewithyourBlockchain.infowallet.

ContentsGettingStartedUpgradingAPIDocumentationRPCAPIInstallationTroubleshootingUsageDevelopmentDeploymentGettingStarted

TousethisAPI,youwillneedtorunsmalllocalservicewhichberesponsibleformanagingyourBlockchain.infowallet.YourapplicationinteractswiththisservicelocallyviaHTTPAPIcalls.

Startbycompletingthefollowingsteps:

FollowtheinstallationinstructionsStarttheserver:$blockchain-wallet-servicestart--port3000Referencethedocumentationandstartinteractingwithyourwalletprogrammatically!

Notethatblockchain-wallet-serviceisdesignedtoberunlocallyonthesamemachineasyourapplicationandthereforewillonlyacceptconnectionsfromlocalhost.Ifyoumodifythisservicetoacceptexternalconnections,besuretoaddtheappropriatefirewallrulestopreventunauthorizeduse.

AnAPIcodeisrequiredforwalletcreationandhigherrequestlimits.Forbasicusage,noAPIcodeisrequired.RequestanAPIcodehere.

Upgrading

IfyoualreadyhaveanapplicationthatusesBlockchain.info'sWalletAPI,youwillneedtocompletethestepsintheGettingStartedsectionaboveandthen,inyourapplicationcode,replacecallstoblockchain.info/merchant/...withlocalhost:<port>/merchant/....

APIDocumentation

Viewtheoriginaldocumentation.

AllendpointspresentintheAPIdocumentationabovearesupportedinBlockchainWalletAPIV2.Thedifferencesbetweentwoare:

The"consolidateaddresses"endpointhasbeenomitted

AllendpointscanbecalledwithGETorPOST,andcanonlybeaccessedfromlocalhost.

CreatinganewBlockchainWallet

Endpoint:/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"}MakePayment

Endpoint:/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-byteinsatoshi

Itisrecommendedthattransactionfeesarespecifiedusingthefee_per_byteparameter,whichwillcomputeyourfinalfeebasedonthesizeofthetransaction.Youcanalsosetastaticfeeusingthefeeparameter,butdoingsomayresultinalowfee-per-byte,leadingtolongerconfirmationtimes.

SampleResponse:

{"to":["1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq"],"from":["17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY"],"amounts":[200000],"fee":1000,"txid":"f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c","success":true}SendtoMany

Endpoint:/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-byteinsatoshi

Itisrecommendedthattransactionfeesarespecifiedusingthefee_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`parameter

SampleResponse:

{"to":["1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq","18fyqiZzndTxdVo7g9ouRogB4uFj86JJiy"],"from":["17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY"],"amounts":[16000,5400030],"fee":2000,"txid":"f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c","success":true}FetchWalletBalance

Endpoint:/merchant/:guid/balance

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(required)

SampleResponse:

{"balance":10000}EnableHDFunctionality

Endpoint:/merchant/:guid/enableHD

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)

ThiswillupgradeawallettoanHD(HierarchicalDeterministic)Wallet,whichallowstheuseofaccounts.SeeBIP32formoreinformationonHDwalletsandaccounts.

ListActiveHDAccounts

Endpoint:/merchant/:guid/accounts

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)ListHDxPubs

Endpoint:/merchant/:guid/accounts/xpubs

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)CreateNewHDAccount

Endpoint:/merchant/:guid/accounts/create

QueryParameters:

label-labeltoassigntothenewlycreatedaccount(optional)password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)GetSingleHDAccount

Endpoint:/merchant/:guid/accounts/:xpub_or_index

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)GetHDAccountReceivingAddress

Endpoint:/merchant/:guid/accounts/:xpub_or_index/receiveAddress

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)CheckHDAccountBalance

Endpoint:/merchant/:guid/accounts/:xpub_or_index/balance

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)ArchiveHDAccount

Endpoint:/merchant/:guid/accounts/:xpub_or_index/archive

QueryParameters:

password-mainwalletpassword(required)api_code-blockchain.infowalletapicode(optional)UnarchiveHDAccount

Endpoint:/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"}RPC

BitcoindcompatibleRPCAPI.Fulldocumentationavailablehere.

StartingtheRPCserver:

$blockchain-wallet-servicestart-rpc[options]

ViewadditionaloptionsandinstructionsunderUsage.

DifferencesfromserverAPI:

Option-rpcsslisnotsupportedMethodlistsinceblockisnotsupportedParamminConfimationsisnotsupportedformethodslistreceivedbyaccountandlistreceivedbyaddressParamminimumConfirmationsisnotsupportedformethodgetbalanceParamconfirmationsisnotsupportedformethodlistaccountsResponsesrepresentingtransactionshaveadifferentformatInstallation

nodejsandnpmarerequiredtoinstallandusethisAPIservice.Installation:

$npminstall-gblockchain-wallet-service

Forthebeststabilityandperformance,makesureyouarealwaysusingthelatestversion.

Tocheckyourversion:

$blockchain-wallet-service-V

Toupdatetothelatestversion:

$npmupdate-gblockchain-wallet-service

Requires:

node>=6.0.0npm>=3.0.0

Ifyouhaveissueswiththeinstallationprocess,seethetroubleshootingsectionbelow.

Troubleshooting

Installationerrors:

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.

Usage

Afterinstallingtheservice,thecommandblockchain-wallet-servicewillbeavailableforuse.

Options-h,--help-outputusageinformation-V,--version-outputtheversionnumber-c,--cwd-usethecurrentdirectoryasthewalletservicemodule(developmentonly)Commandsstart

Usage: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-rpc

Usage: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.

Examples

TostarttheWalletAPIserviceonport3000:

$blockchain-wallet-servicestart--port3000DevelopmentClonethisrepoRunyarn--ignore-enginesRunyarnstartDevserverisnowrunningonport3000

Ifyouaredevelopingblockchain-wallet-clientalongsidethismodule,itisusefultocreateasymlinktomy-wallet-v3:

$ln-s../path/to/my-wallet-v3node_modules/blockchain-wallet-clientTesting$yarntestConfiguration

Optionalparameterscanbeconfiguredina.envfile:

PORT-portnumberforrunningdevserver(default:3000)BIND-ipaddresstobindtheserviceto(default:127.0.0.1)Deployment

Ifyouwanttouseblockchain-wallet-serviceinyourUNIXproductionserver,youjusthavetorun:

$nohupblockchain-wallet-servicestart--port3000&
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论