Testrpc

創建新令牌教程

  • February 25, 2018

我正在關注有關創建新令牌的本教程:

https://hashnode.com/post/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts-cjcs8dfes00apmdwthw03c2jq

it('one ETH should buy 5 Hashnode Tokens in PreICO', function(done){
       HashnodeCrowdsale.deployed().then(async function(instance) {
           const data = await instance.sendTransaction({ from: accounts[7], value: web3.toWei(1, "ether")});
           const tokenAddress = await instance.token.call();
           const hashnodeToken = HashnodeToken.at(tokenAddress);
           const tokenAmount = await hashnodeToken.balanceOf(accounts[7]);
           assert.equal(tokenAmount.toNumber(), 5000000000000000000, 'The sender didn\'t receive the tokens as per PreICO rate');
           done();
      });
   });

**問題1:**很多人在sendTransaction 中沒有指定“to”。預設情況下,它會轉到部署實例的位置嗎?不是下面的地址:0x5AEDA56215b167893e80B4fE645BA6d5Bab767DE。這是雜湊節點令牌的地址嗎?

module.exports = function(deployer) {
 const startTime = Math.round((new Date(Date.now() - 86400000).getTime())/1000); // Yesterday
 const endTime = Math.round((new Date().getTime() + (86400000 * 20))/1000); // Today + 20 days
 deployer.deploy(HashnodeCrowdsale, 
   startTime, 
   endTime,
   5, 
   "0x5AEDA56215b167893e80B4fE645BA6d5Bab767DE", // Replace this wallet address with the last one (10th account) from Ganache UI. This will be treated as the beneficiary address. 
   2000000000000000000, // 2 ETH
   500000000000000000000 // 500 ETH
 );
};

**問題 2:**在上面的測試中,帳戶

$$ 7 $$用於發送乙太幣。然後在下面它使用 balanceOf 來確定賬戶餘額$$ 7 $$. 是不是表示同一個賬戶地址ie 7 存放ether 和hashnode 代幣?

contract HashnodeCrowdsale is CappedCrowdsale, RefundableCrowdsale {
....
function forwardFunds() internal {
     if (stage == CrowdsaleStage.PreICO) {
         wallet.transfer(msg.value);
         EthTransferred("forwarding funds to wallet");
     } else if (stage == CrowdsaleStage.ICO) {
         EthTransferred("forwarding funds to refundable vault");
         super.forwardFunds();
     }
 }
}

HashnodeCrowdsale 繼承自 CappedCrowdsale,後者繼承自 Crowdsale。

問題3: forwardFunds 覆蓋了Crowsdale 中的forwardFunds,但是在呼叫forwardFunds 時在Crowdsale 內部呼叫了HashnodeCrowdsale 中的那個。它不應該是 Crowdsale 內部的那個,因為 Crowdsale 不知道 HashnodeCrowdsale 正在繼承 Crowdsale。相反,Hashnodecrowdsale 知道它是從 Crowdsale 繼承的

**答案 1:**如果你這樣做instance.sendTransaction而不是web3.eth.sendTransactionthento已經分配為instance.

**答案 2:**是的。它基本上意味著該帳戶

$$ 7 $$創建了眾籌,並且在契約創建期間將一些代幣(通常是全部金額)分配給了他的帳戶。 **答案3:**完全不清楚你在問什麼。您提供了一段程式碼,您的問題是關於 3 個契約,您說什麼crowdsale時候有 3 個契約名為******Crowdsale.

同時,我的假設是您會感到困惑,因為 HashnodeCrowdsale 中的某些方法在forwardFunds內部呼叫,該方法內部使用的super.語法在底層呼叫 inhereted 方法forwardFunds

引用自:https://ethereum.stackexchange.com/questions/40824