關於區塊鏈代幣DAPP專案系統開發(Demo)

Tg_StPv888發表於2023-04-10

  區塊鏈是從BTC系統中提煉出來的一種底層支撐技術,Token原本是區塊鏈上激勵“礦工”的一種經濟手段,在加密數字貨幣的發展過程中,有大量的組織也希望能夠發行自己的Token,區塊鏈2.0——ETH及其訂立的ERC20標準應用而生,基於這個平臺和標準,任何人和組織都可以在ETH上發行自己定義的Token,極大地降低了發行的難度和速度,Token開始以代幣的身份為大眾所熟知。


  Deployer API deployer物件提供了方法用於簡化智慧合約的部署。deployer.deploy(contract,args…,options)引數contract為使用artifacts.require引用的智慧合約物件。引數args...為智慧合約的建構函式的引數,用於初始化智慧合約。引數options用於指定from,gas及overwrite等資訊,overwrite用於重新部署某個已經完成部署的智慧合約,預設的options引數在bottle.js檔案中配置


  例子:


  //Deploy a single contract without constructor arguments


  deployer.deploy(A);


  //Deploy a single contract with constructor arguments


  deployer.deploy(A,arg1,arg2,...);


  //Don't deploy this contract if it has already been deployed


  deployer.deploy(A,{overwrite:false});


  //Set a maximum amount of gas and`from`address for the deployment


  deployer.deploy(A,{gas:4612388,from:"0x...."});


  //External dependency example:


  //


  //For this example,our dependency provides an address when we're deploying to the


  //live network,but not for any other networks like testing and development.


  //When we're deploying to the live network we want it to use that address,but in


  //testing and development we need to deploy a version of our own.Instead of writing


  //a bunch of conditionals,we can simply use the`overwrite`key.


  deployer.deploy(SomeDependency,{overwrite:false});


  透過promise物件可以執行任意的部署步驟並呼叫指定的智慧合約內部方法來進行互動


  例子:


  var ERC20=artifacts.require("../contracts/Erc20.c")


  module.exports=function(deployer,a){


  deployer.deploy(ERC20,"1000000","bitcoin","BTC").then(function(instance){


  deploy=instance;


  return deploy.GetTotalSupply()


  }).then(function(totalSupply){


  console.log("totalSupply",totalSupply.toString());


  return deploy.GetDecimals();


  }).then(function(decimals){


  console.log("decimals",decimals.toString());


  return deploy.GetTokenName();


  }).then(function(tokenName){


  console.log("tokenName",tokenName);


  return deploy.GetAmount("0x122369f04f32269598789998de33e3d56e2c507a")


  }).then(function(balance){


  console.log("balance",balance.toString());


  })


  };


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70016646/viewspace-2944614/,如需轉載,請註明出處,否則將追究法律責任。

相關文章