JSONRPCserver
INBGOOfficialgolangimplementationoftheInsightChain
BuildingFirst,youneedbothaGo(version1.10orlater)andaCcompiler.
makeginbor,tobuildthefullsuiteofutilities:
makeallRunningGoingthroughallthepossiblecommandlineflagsisoutofscopehere,butwe'veenumeratedafewcommonparametercombostogetyouuptospeedquicklyonhowyoucanrunyourownginbinstance.
FullnodeonthemainINBnetworkByfarthemostcommonscenarioispeoplewantingtosimplyinteractwiththeINBnetwork:createaccounts;transferfunds;Mortgageorrelease;deployandinteractwithcontracts.Forthisparticularuse-casetheuserdoesn'tcareaboutyears-oldhistoricaldata,sowecanfast-syncquicklytothecurrentstateofthenetwork.Todoso:
$ginbconsoleFullsupernodeonthemainINBnetworkIfyouwanttobeasupernodeandhavetherighttomine,youhavetogetsomeoneelse'svoteinadvanceandonlythe21nodeswiththehighestnumberofvoteshavethechance.
Ifyoumeettheaboveconditions,pleasecontinue.
Youneedtomakeyournodeidbeforeyoustartthenetwork.
$ginbnodekey[datadir]Thereturnednodeid(asenodes.id)needstobeconfiguredinthegenesis.jsonfile,aswellasyourip,port,name,countryandsoon.DataprovidesomeotherK-Vinformationifyouwanttostore
{"config":{"chainId":891,"homesteadBlock":0,"eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"vdpos":{"period":3,"signerPeriod":3,"signerBlocks":6,"epoch":201600,"maxSignersCount":21,"minVoterBalance":1000000000000000000,"genesisTimestamp":1561544470,"signers":["0x891b2388ce73356917b21ca54f3039cbdfc29313","0x4643ce2d6d4fe02e2b57070806364dde9eb8cac9","0x230cf5081833c4f16e69e102ea00a4583a33cb11"],"enodes":[{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},]}},"coinbase":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","gasLimit":"0x2fefd8","nonce":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00","alloc":{"891b2388ce73356917b21ca54f3039cbdfc29313":{"balance":"0"},"4643ce2d6d4fe02e2b57070806364dde9eb8cac9":{"balance":"0"},"230cf5081833c4f16e69e102ea00a4583a33cb11":{"balance":"0"}}}Vdposisnecessary.Periodrepresentsthenumberofsecondsbetweenblocks,signerPeriodrepresentsthenumberofsecondsblocksbetweentwosupernodes,signerBlocksrepresentsthenumberofpackagedblockspersupernode,epochrepresentstheintervalbetweenemptyingvotinginformationandre-voting,andmaxSignersCountrepresentsthemaximumnumberofsupernodes.Enodesrepresentsinformationaboutallsupernodesthatwerefirstvotedforandeveryoneautomaticallyconnectstothesupernodes'networks.
Tip:TheneveryoneinitializestheGenesisBlockwiththesamesetofgenesis.jsonfiles
$ginbinitpath/to/genesis.jsonFinallystartthenetwork
$ginb--datadirdata1/--networkid891--nodiscover--rpcport6002--port30002consoleFullnodeontheINBtestnetworkTransitioningtowardsdevelopers,ifyou'dliketoplayaroundwithcreatingINBcontracts,youalmostcertainlywouldliketodothatwithoutanyrealmoneyinvolveduntilyougetthehangoftheentiresystem.Inotherwords,insteadofattachingtothemainnetwork,youwanttojointhetestnetworkwithyournode,whichisfullyequivalenttothemainnetwork,butwithplay-inberonly.
$ginb--testnetconsoleTheconsolesubcommandhastheexactsamemeaningasaboveandtheyareequallyusefulonthetestnettoo.Pleaseseeabovefortheirexplanationsifyou'veskippedhere.
Specifyingthe--testnetflag,however,willreconfigureyourginbinstanceabit:
Insteadofusingthedefaultdatadirectory(~/.inbonLinuxforexample),ginbwillnestitselfoneleveldeeperintoatestnetsubfolder(~/.inb/testnetonLinux).Note,onOSXandLinuxthisalsomeansthatattachingtoarunningtestnetnoderequirestheuseofacustomendpointsinceginbattachwilltrytoattachtoaproductionnodeendpointbydefault.E.g.ginbattach<datadir>/testnet/ginb.ipc.Windowsusersarenotaffectedbythis.InsteadofconnectingthemainINBnetwork,theclientwillconnecttothetestnetwork,whichusesdifferentP2Pbootnodes,differentnetworkIDsandgenesisstates.Note:Althoughtherearesomeinternalprotectivemeasurestopreventtransactionsfromcrossingoverbetweenthemainnetworkandtestnetwork,youshouldmakesuretoalwaysuseseparateaccountsforplay-moneyandreal-money.Unlessyoumanuallymoveaccounts,ginbwillbydefaultcorrectlyseparatethetwonetworksandwillnotmakeanyaccountsavailablebetweenthem.
###ConfigurationAsanalternativetopassingthenumerousflagstothe`ginb`binary,youcanalsopassaconfigurationfilevia:```shell$geinb--config/path/to/your_config.tomlTogetanideahowthefileshouldlooklikeyoucanusethedumpconfigsubcommandtoexportyourexistingconfiguration:
$ginb--your-favourite-flagsdumpconfigProgrammaticallyinterfacingginbnodesAsadeveloper,soonerratherthanlateryou'llwanttostartinteractingwithginbandtheInsightnetworkviayourownprogramsandnotmanuallythroughtheconsole.Toaidthis,ginbhasbuilt-insupportforaJSON-RPCbasedAPIsand[ginbspecificAPIs]ThesecanbeexposedviaHTTP,WebSocketsandIPC(UNIXsocketsonUNIXbasedplatforms,andnamedpipesonWindows).
TheIPCinterfaceisenabledbydefaultandexposesalltheAPIssupportedbyginb,whereastheHTTPandWSinterfacesneedtomanuallybeenabledandonlyexposeasubsetofAPIsduetosecurityreasons.Thesecanbeturnedon/offandconfiguredasyou'dexpect.
HTTPbasedJSON-RPCAPIoptions:
--rpcEnabletheHTTP-RPCserver--rpcaddrHTTP-RPCserverlisteninginterface(default:localhost)--rpcportHTTP-RPCserverlisteningport(default:8545)--rpcapiAPI'sofferedovertheHTTP-RPCinterface(default:inb,net,web3)--rpccorsdomainCommaseparatedlistofdomainsfromwhichtoacceptcrossoriginrequests(browserenforced)--wsEnabletheWS-RPCserver--wsaddrWS-RPCserverlisteninginterface(default:localhost)--wsportWS-RPCserverlisteningport(default:8546)--wsapiAPI'sofferedovertheWS-RPCinterface(default:inb,net,web3)--wsoriginsOriginsfromwhichtoacceptwebsocketsrequests--ipcdisableDisabletheIPC-RPCserver--ipcapiAPI'sofferedovertheIPC-RPCinterface(default:admin,debug,inb.vdpos,miner,net,personal,shh,txpool,web3)--ipcpathFilenameforIPCsocket/pipewithinthedatadir(explicitpathsescapeit)You'llneedtouseyourownprogrammingenvironments'capabilities(libraries,tools,etc)toconnectviaHTTP,WSorIPCtoaginbnodeconfiguredwiththeaboveflagsandyou'llneedtospeakJSON-RPConalltransports.Youcanreusethesameconnectionformultiplerequests!
Note:PleaseunderstandthesecurityimplicationsofopeningupanHTTP/WSbasedtransportbeforedoingso!HackersontheinternetareactivelytryingtosubvertInsightnodeswithexposedAPIs!Further,allbrowsertabscanaccesslocallyrunningwebservers,somaliciouswebpagescouldtrytosubvertlocallyavailableAPIs!
OperatingaprivatenetworkMaintainingyourownprivatenetworkismoreinvolvedasalotofconfigurationstakenforgrantedintheofficialnetworksneedtobemanuallysetup.
DefiningtheprivategenesisstateFirst,you'llneedtocreatethegenesisstateofyournetworks,whichallnodesneedtobeawareofandagreeupon.ThisconsistsofasmallJSONfile(e.g.callitgenesis.json):
{"config":{"chainId":891,"homesteadBlock":0,"eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"vdpos":{"period":3,"signerPeriod":3,"signerBlocks":6,"epoch":201600,"maxSignersCount":21,"minVoterBalance":1000000000000000000,"genesisTimestamp":1561544470,"signers":["0x891b2388ce73356917b21ca54f3039cbdfc29313","0x4643ce2d6d4fe02e2b57070806364dde9eb8cac9","0x230cf5081833c4f16e69e102ea00a4583a33cb11"],"enodes":[{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},]}Theabovefieldsshouldbefineformostpurposes,althoughwe'drecommendchangingthenoncetosomerandomvaluesoyoupreventunknownremotenodesfrombeingabletoconnecttoyou.Ifyou'dliketopre-fundsomeaccountsforeasiertesting,youcanpopulatetheallocfieldwithaccountconfigs:
"alloc":{"0x0000000000000000000000000000000000000001":{"balance":"111111111"},"0x0000000000000000000000000000000000000002":{"balance":"222222222"}}WiththegenesisstatedefinedintheaboveJSONfile,you'llneedtoinitializeeveryginbnodewithitpriortostartingituptoensureallblockchainparametersarecorrectlyset:
$ginbinitpath/to/genesis.jsonCreatingtherendezvouspointWithallnodesthatyouwanttoruninitializedtothedesiredgenesisstate,you'llneedtostartabootstrapnodethatotherscanusetofindeachotherinyournetworkand/orovertheinternet.Thecleanwayistoconfigureandrunadedicatedbootnode:
$bootnode--genkey=boot.key$bootnode--nodekey=boot.keyNote:Youcouldalsouseafull-fledgedginbnodeasabootnode,butit'sthelessrecommendedway.
StartingupyourmembernodesWiththebootnodeoperationalandexternallyreachable(youcantrytelnet<ip><port>toensureit'sindeedreachable),starteverysubsequentginbnodepointedtothebootnodeforpeerdiscoveryviathe--bootnodesflag.Itwillprobablyalsobedesirabletokeepthedatadirectoryofyourprivatenetworkseparated,sodoalsospecifyacustom--datadirflag.
$ginb--datadir=path/to/custom/data/folder--bootnodes=<bootnode-enode-url-from-above>Note:Sinceyournetworkwillbecompletelycutofffromthemainandtestnetworks,you'llalsoneedtoconfigureaminertoprocesstransactionsandcreatenewblocksforyou.
RunningaprivateminerMiningonthepublicInsightnetworkisacomplextaskasit'sonlyfeasibleusingGPUs,requiringanOpenCLorCUDAenabledinbminerinstance.Forinformationonsuchasetup
Inaprivatenetworksetting,howeverasingleCPUminerinstanceismorethanenoughforpracticalpurposesasitcanproduceastablestreamofblocksatthecorrectintervalswithoutneedingheavyresources(considerrunningonasinglethread,noneedformultipleoneseither).Tostartaginbinstanceformining,runitwithallyourusualflags,extendedby:
$ginb<usual-flags>--mine--minerthreads=1--inberbase=0x0000000000000000000000000000000000000000
评论