BlockchaiWalletAPIV2
ProgrammaticallyiterfacewithyourBlockchai.ifowallet.
CotetsGettigStartedUpgradigAPIDocumetatioRPCAPIIstallatioTroubleshootigUsageDevelopmetDeploymetGettigStartedTousethisAPI,youwilleedtorusmalllocalservicewhichberesposibleformaagigyourBlockchai.ifowallet.YourapplicatioiteractswiththisservicelocallyviaHTTPAPIcalls.
Startbycompletigthefollowigsteps:
FollowtheistallatioistructiosStarttheserver:$blockchai-wallet-servicestart--port3000Referecethedocumetatioadstartiteractigwithyourwalletprogrammatically!Notethatblockchai-wallet-serviceisdesigedtoberulocallyothesamemachieasyourapplicatioadthereforewillolyacceptcoectiosfromlocalhost.Ifyoumodifythisservicetoacceptexteralcoectios,besuretoaddtheappropriatefirewallrulestoprevetuauthorizeduse.
AAPIcodeisrequiredforwalletcreatioadhigherrequestlimits.Forbasicusage,oAPIcodeisrequired.RequestaAPIcodehere.
UpgradigIfyoualreadyhaveaapplicatiothatusesBlockchai.ifo'sWalletAPI,youwilleedtocompletethestepsitheGettigStartedsectioaboveadthe,iyourapplicatiocode,replacecallstoblockchai.ifo/merchat/...withlocalhost:<port>/merchat/....
APIDocumetatioViewtheorigialdocumetatio.
AlledpoitspresetitheAPIdocumetatioabovearesupportediBlockchaiWalletAPIV2.Thedifferecesbetweetwoare:
The"cosolidateaddresses"edpoithasbeeomittedAlledpoitscabecalledwithGETorPOST,adcaolybeaccessedfromlocalhost.
CreatigaewBlockchaiWalletEdpoit:/api/v2/create
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(required)priv-privatekeytoimportitowalletasfirstaddress(optioal)label-labeltogivetothefirstaddressgeeratedithewallet(optioal)email-emailtoassociatewiththeewlycreatedwallet(optioal)SampleRespose:
{"guid":"05f290be-dbef-4636-a809-868893c51711","address":"13R9dBgKwBP29JKo11zhfi74YuBsMxJ4qY","label":"Maiaddress"}MakePaymetEdpoit:/merchat/:guid/paymet
QueryParameters:
to-bitcoiaddresstosedto(required)amout-amoutisatoshitosed(required)password-maiwalletpassword(required)secod_password-secodwalletpassword(required,olyifsecodpasswordiseabled)api_code-blockchai.ifowalletapicode(optioal)from-bitcoiaddressoraccoutidextosedfrom(optioal)fee-specifytrasactiofeeisatoshifee_per_byte-specifytrasactiofee-per-byteisatoshiItisrecommededthattrasactiofeesarespecifiedusigthefee_per_byteparameter,whichwillcomputeyourfialfeebasedothesizeofthetrasactio.Youcaalsosetastaticfeeusigthefeeparameter,butdoigsomayresultialowfee-per-byte,leadigtologercofirmatiotimes.
SampleRespose:
{"to":["1A8JiWcwvpY7tAopUkSGuEYHmzGYfZPiq"],"from":["17p49XUC2fw4F53WjZqYAm4APKqhNPEkY"],"amouts":[200000],"fee":1000,"txid":"f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c","success":true}SedtoMayEdpoit:/merchat/:guid/sedmay
QueryParameters:
recipiets-aURIecodedJSONobject,withbitcoiaddressesaskeysadthesatoshiamoutsasvalues(required,seeexamplebelow)password-maiwalletpassword(required)secod_password-secodwalletpassword(required,olyifsecodpasswordiseabled)api_code-blockchai.ifowalletapicode(optioal)from-bitcoiaddressoraccoutidextosedfrom(optioal)fee-specifytrasactiofeeisatoshifee_per_byte-specifytrasactiofee-per-byteisatoshiItisrecommededthattrasactiofeesarespecifiedusigthefee_per_byteparameter,whichwillcomputeyourfialfeebasedothesizeofthetrasactio.Youcaalsosetastaticfeeusigthefeeparameter,butdoigsomayresultialowfee-per-byte,leadigtologercofirmatiotimes.
URIEcodigaJSONobjectiJavaScript:
varmyObject={address1:10000,address2:50000};varmyJSONStrig=JSON.strigify(myObject);//`ecodeURICompoet`isaglobalfuctiovarmyURIEcodedJSONStrig=ecodeURICompoet(myJSONStrig);//use`myURIEcodedJSONStrig`asthe`recipiets`parameterSampleRespose:
{"to":["1A8JiWcwvpY7tAopUkSGuEYHmzGYfZPiq","18fyqiZzdTxdVo7g9ouRogB4uFj86JJiy"],"from":["17p49XUC2fw4F53WjZqYAm4APKqhNPEkY"],"amouts":[16000,5400030],"fee":2000,"txid":"f322d01ad784e5deeb25464a5781c3b20971c1863679ca506e702e3e33c18e9c","success":true}FetchWalletBalaceEdpoit:/merchat/:guid/balace
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(required)SampleRespose:
{"balace":10000}EableHDFuctioalityEdpoit:/merchat/:guid/eableHD
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)ThiswillupgradeawallettoaHD(HierarchicalDetermiistic)Wallet,whichallowstheuseofaccouts.SeeBIP32formoreiformatiooHDwalletsadaccouts.
ListActiveHDAccoutsEdpoit:/merchat/:guid/accouts
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)ListHDxPubsEdpoit:/merchat/:guid/accouts/xpubs
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)CreateNewHDAccoutEdpoit:/merchat/:guid/accouts/create
QueryParameters:
label-labeltoassigtotheewlycreatedaccout(optioal)password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)GetSigleHDAccoutEdpoit:/merchat/:guid/accouts/:xpub_or_idex
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)GetHDAccoutReceivigAddressEdpoit:/merchat/:guid/accouts/:xpub_or_idex/receiveAddress
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)CheckHDAccoutBalaceEdpoit:/merchat/:guid/accouts/:xpub_or_idex/balace
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)ArchiveHDAccoutEdpoit:/merchat/:guid/accouts/:xpub_or_idex/archive
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)UarchiveHDAccoutEdpoit:/merchat/:guid/accouts/:xpub_or_idex/uarchive
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)ListAddresses(deprecated,usetheHDAPIistead)Edpoit:/merchat/:guid/list
QueryParameters:
password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)SampleRespose:
{"addresses":[{"balace":79434360,"address":"1A8JiWcwvpY7tAopUkSGuEYHmzGYfZPiq","label":"MyWallet","total_received":453300048335},{"balace":0,"address":"17p49XUC2fw4F53WjZqYAm4APKqhNPEkY","total_received":0}]}FetchAddressBalace(deprecated,usetheHDAPIistead)Edpoit:/merchat/:guid/address_balace
QueryParameters:
address-addresstofetchbalacefor(required)password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)Note:ulikethehostedAPI,thereisooptioofacofirmatiosparameterforspecifyigmiimumcofirmatios.
SampleRespose:
{"balace":129043,"address":"19r7jAbPDtfTKQ9VJpvDzFFxCjUJFKesVZ","total_received":53645423}GeerateAddress(deprecated,usetheHDAPIistead)Edpoit:/merchat/:guid/ew_address
QueryParameters:
password-maiwalletpassword(required)label-labeltogivetotheaddress(optioal)api_code-blockchai.ifowalletapicode(optioal)SampleRespose:
{"address":"18fyqiZzdTxdVo7g9ouRogB4uFj86JJiy","label":"MyNewAddress"}ArchiveAddress(deprecated,usetheHDAPIistead)Edpoit:/merchat/:guid/archive_address
QueryParameters:
address-addresstoarchive(required)password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)SampleRespose:
{"archived":"18fyqiZzdTxdVo7g9ouRogB4uFj86JJiy"}UarchiveAddress(deprecated,usetheHDAPIistead)Edpoit:/merchat/:guid/uarchive_address
QueryParameters:
address-addresstouarchive(required)password-maiwalletpassword(required)api_code-blockchai.ifowalletapicode(optioal)SampleRespose:
{"active":"18fyqiZzdTxdVo7g9ouRogB4uFj86JJiy"}RPCBitcoidcompatibleRPCAPI.Fulldocumetatioavailablehere.
StartigtheRPCserver:
$blockchai-wallet-servicestart-rpc[optios]ViewadditioaloptiosadistructiosuderUsage.
DifferecesfromserverAPI:
Optio-rpcsslisotsupportedMethodlistsiceblockisotsupportedParammiCofimatiosisotsupportedformethodslistreceivedbyaccoutadlistreceivedbyaddressParammiimumCofirmatiosisotsupportedformethodgetbalaceParamcofirmatiosisotsupportedformethodlistaccoutsResposesrepresetigtrasactioshaveadifferetformatIstallatioodejsadpmarerequiredtoistalladusethisAPIservice.Istallatio:
$pmistall-gblockchai-wallet-serviceForthebeststabilityadperformace,makesureyouarealwaysusigthelatestversio.
Tocheckyourversio:
$blockchai-wallet-service-VToupdatetothelatestversio:
$pmupdate-gblockchai-wallet-serviceRequires:
ode>=6.0.0pm>=3.0.0Ifyouhaveissueswiththeistallatioprocess,seethetroubleshootigsectiobelow.
TroubleshootigIstallatioerrors:
IfyouaregettigEACCESSorpermissios-relatederrors,itmightbeecessarytorutheistallasroot,usigthesudocommad.
Ifyouaregettigerrorscocerigode-gyporpytho,istallwithpmistall--o-optioal
Startuperrors:
Ifstartupfailswith/usr/bi/ev:ode:Nosuchfileordirectory,it'spossibleodeisotistalled,orwasistalledwithadifferetame(Ubutu,forexample,istallsodeasodejs).Ifodewasistalledwithadifferetame,createasymliktoyourodebiary:sudol-s/usr/bi/odejs/usr/bi/ode,oristallodethroughNodeVersioMaager.Rutimeerrors:
IfyouareseeigaTypeErrorclaimigthataobjecthasomethod'compare',itisbecauseyouareoaversioofNodeoldertha0.12,beforethecomparemethodwasaddedtoBuffers.TryupgradigtoatleastNodeversio0.12.
Ifyouaregettigwalletdecryptioerrorsdespitehavigcorrectcredetials,theit'spossiblethatyoudoothaveJavaistalled,whichisrequiredbyadepedecyofthemy-wallet-v3module.NothavigJavaistalleddurigthepmistallprocesscaresultitheiabilitytodecryptwallets.DowloadtheJDKfromhereforMacorbyruigapt-getistalldefault-jdkodebia-basedliuxsystems.
TimeoutErrors:
Ifyouaregettigatimeoutrespose,additioalauthorizatiofromyourblockchaiwalletmayberequired.ThiscaoccurwheusigaurecogizedbrowserorIPaddress.AemailauthorizigtheAPIaccessattemptwillbesettotheregistereduserthatwillrequireactioiordertoauthorizefuturerequests.Ifthissectiodidothelp,pleaseopeagithubissueorvisitoursupportceter.
UsageAfteristalligtheservice,thecommadblockchai-wallet-servicewillbeavailableforuse.
Optios-h,--help-outputusageiformatio-V,--versio-outputtheversioumber-c,--cwd-usethecurretdirectoryasthewalletservicemodule(developmetoly)CommadsstartUsage:blockchai-wallet-servicestart[optios]
Thiscommadwillstarttheservice,makigBlockchaiWalletAPIV2availableoaspecifiedport.
Commadoptios:
-h,--help-outputusageiformatio-p,--port-portumbertorutheservero(defaultsto3000)-b,--bid-bidtoaspecificip(defaultsto127.0.0.1,otethatbidigtoaipotherthathiscaleadtosecurityvulerabilities)--ssl-key-thepathtoyoursslkey(optioal)--ssl-cert-thepathtoyoursslcertificate(optioal)Toopetheservicetoallicomigcoectios,bidto0.0.0.0.
start-rpcUsage:blockchai-wallet-servicestart-rpc[optios]
ThiscommadwillstarttheJSONRPCserver.
Optios:
-k,--key-apicodetouseforserverrequests(requiredoptio)-p,--rpcport-rpcserverport(default:8000)-b,--bid-bidtoaspecificip(defaultsto127.0.0.1,otethatbidigtoaipotherthathiscaleadtosecurityvulerabilities)GetaAPIcodehere.
ExamplesTostarttheWalletAPIserviceoport3000:
$blockchai-wallet-servicestart--port3000DevelopmetCloethisrepoRuyar--igore-egiesRuyarstartDevserverisowruigoport3000Ifyouaredevelopigblockchai-wallet-clietalogsidethismodule,itisusefultocreateasymliktomy-wallet-v3:
$l-s../path/to/my-wallet-v3ode_modules/blockchai-wallet-clietTestig$yartestCofiguratioOptioalparameterscabecofiguredia.evfile:
PORT-portumberforruigdevserver(default:3000)BIND-ipaddresstobidtheserviceto(default:127.0.0.1)DeploymetIfyouwattouseblockchai-wallet-serviceiyourUNIXproductioserver,youjusthavetoru:
$ohupblockchai-wallet-servicestart--port3000&









评论