BlockchainStore

我要开发同款
匿名用户2021年11月30日
33阅读
所属分类、Web3、区块链
授权协议MIT License

作品详情

RetailStoreonBlockchainAbout

ThisisaSmartContractthatrunsonEthereum

ItiswritteninSolidityandrepresentsaretailstore.Itsupportscustomerandproductregistrations.Everyregisteredcustomerownsashoppingcarttocollectproductsbeforecheckingout.

Dapp

Inthisearlyversionthere'snoproperwebinterfaceavailableandyou'llhavetousetruffleconsoletoaccessthecontract.InfutureI'llprovideaweb-appwritteninAngular4.x.Theultimategoalistonotonlyproduceaweb-sitebutacompleteweb-platformbehindit.Embeddingareal-worldbusinessmodelintosomethinglikeaDAppimpliescertainfunctionalities:

database[youcertainlydon'twanttostoreyourcustomerspersonaldataontheblockchain]

errorhandling[there'snoerror-handlinginEthereumbutyourbusinessisn'tEthereum]

transactions[Ethereumtransactionsaren'tyourbusinesstransactions]

unavoidableupdates[nocodeiseternal]

automaticbackups[I'mrepeatingmyself...seedatabasesabove]

backendAPIs[forexample:detailedproductinfos,currencyconversions,geo-locationsetc.]

...andmanyotherthings.

Givingcustomersaninterfacewheretheycanaddorremoveproductsto/fromtheirshoppingcartsisimportantbutnottheultimategoal.TheshoppingexperienceontheUIandasophisticatedbusinesslogicinthebackendmustbothexisttosupporteachother.Aslongaswecan'tputanon-public&fastdatabaseonEthereumwe'llhavetomaintainitsomewhereelse.AndtoachievethisgoalourDappwillrelyonbackendAPIs.

Currently,asimpledemotoplayaroundwithweb3-APIisavailable.Togettheabovedemoworkingpleasefollowthesesteps:

CompilethecontractswithtrufflecompileThenmovethenewlycreatedbuildfoldertosrcNowyoucanboottheappvianpmrunstart:hmrTokens

StoreTokenswillsoonbesupported.Onecouldusethemtopurchasegoodsinthestoreorforinitialcoinofferings.Forexample:you'replanningtoopenastorethatdealswithcertainpopulargoodsbutyou'reunsurehowmanypotentialcustomersareoutthere.Nowyoucouldsimplybuysomeethersorothercoinstofinanceyourstore(topaygoodsinadvance,hireadevtocodeaproperDappforyourcustomersetc.).Noweverythingdependsonhowsuccessfulyourbusinesswillbe.Youmayormaynotbeabletosustainit.

Asweallknowtherearealwayscertainriskstotakecareofandthat'swhypeopletrytoconvinceotherpeopletosupporttheirbusinessideas.So,youdecidetosellsharesofyournascentbusinesstointerestedparties.Youcreateaproperbusinessinfomaterial,forexampleaweb-sitethatdescribesyourbusiness,howitshouldlooklike,whatarepotentialrisksetc.Yougenerateacertainamountoftokensbasedonapricethatcouldbefixedornot.Let'ssayyousell1MyStoreTokenfor0.001ETH.AdditionallyyoucandeterminecertainlimitsandhowlongyourICOwilllast.Ofcoursethere'snoobligationtocreateallofyourtokensinadvance.YoucouldeasilydefineadynamictokensupplythatdependsonincomingETHs.

Untilthefirstworkingversiongetsoutyoucantestthecurrentdevelopmentintruffleconsole:

Declareareferencevariablefordeployedtokencontract.

vartoken;

GetitsreferenceviaJSPromise.

BaseStoreToken.deployed().then(d=>token=d);

Displayinitialtokensupply.

token.initialSupply();

Transfer10tokensfromdefaultaddresstoweb3.eth.accounts[1]

token.transfer(web3.eth.accounts[1],10);

APINameGroupSignatureUsageReturnstransferOwnershipowneraddressstore.transferOwnership(new_owner_address)registerProductowneruint256,bytes32,bytes32,uint,uintstore.registerProduct(id,name,description,price,default_amount)boolderegisterProductowneruint256store.deregisterProduct(id)boolgetProductcustomeruint256store.getProduct(id)(bytes32name,bytes32description,uint256price,uint256default_amount)registerCustomerowneraddress,bytes32,uint256store.registerCustomer(cust_address,cust_name,cust_balance)boolderegisterCustomerowneraddressstore.deregisterCustomer(cust_address)boolinsertProductIntoCartcustomeruint256store.insertProductIntoCart(prod_id)(boolsuccess,uint256position_in_prod_mapping)removeProductFromCartcustomeruintstore.removeProductFromCart(prod_position_in_mapping)firesaneventonsuccessfulremovalgetCartcustomerstore.getCart()(uint256[]memoryproduct_ids,uint256completeSum)checkoutCartcustomerstore.checkoutCart()boolemptyCartcustomerstore.emptyCart()boolgetBalancecustomerstore.getBalance()uint256renameStoreToownerbytes32store.renameStoreTo(new_store_name)boolUsage

First,activatealocaltest-blockchainwithtestrpc.Ifyoudon'thaveitjusttypenpminstall-gethereumjs-testrpcandletNPMinstallitforyou.

Second,gointotherootofthisprojectandexecutetrufflecompileandtrufflemigrate(whenchangingthecodeduringlive-testingusetrufflemigrate--resetinstead).

Third,jumpintotruffle'sconsolewithtruffleconsole.NowyoucanusethelocalBlockchaintoplaywiththeStore

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

评论