solidity 合約開發(fā)測(cè)試2--部署自己的代幣合約

發(fā)布自己的代幣到BSC測(cè)試鏈

  • 錯(cuò)誤一:Gas estimation failed X nt Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Returned error: ["jsonrpc"."2.0" "error" "invalid opcode: opcode 0x5f not defined" "id" 5500127351776497}
    因?yàn)榘姹静捎玫?code>0.8.21岸浑,改為0.8.19
該編譯器將默認(rèn)目標(biāo) EVM 版本切換為 Shanghai忽洛,
這意味著生成的字節(jié)碼將包含 PUSH0 操作碼厘托。
如果您打算部署在主網(wǎng)以外的鏈上茄猫,
例如可能尚不支持 PUSH0 的 L2 鏈梳侨,請(qǐng)務(wù)必選擇適當(dāng)?shù)?EVM 版本,
否則合約部署將失敗
  • 錯(cuò)誤二:
    creation of Standard_Token errored: Returned error: {"jsonrpc":"2.0","error":"[ethjs-query] while formatting outputs from RPC '{\"value\":{\"code\":-32603,\"data\":{\"code\":-32000,\"message\":\"transaction underpriced\"}}}'","id":8421776024947773}
    預(yù)估的gas太低了总寒,彈出的小狐貍點(diǎn)擊建議的網(wǎng)站播瞳,選擇高級(jí),設(shè)置5起步
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface Token {

    /// @param _owner The address from which the balance will be retrieved
    /// @return balance the balance
    function balanceOf(address _owner) external view returns (uint256 balance);

    /// @notice send `_value` token to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return success Whether the transfer was successful or not
    function transfer(address _to, uint256 _value)  external returns (bool success);

    /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
    /// @param _from The address of the sender
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return success Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);

    /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _value The amount of wei to be approved for transfer
    /// @return success Whether the approval was successful or not
    function approve(address _spender  , uint256 _value) external returns (bool success);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return remaining Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender) external view returns (uint256 remaining);

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

contract Standard_Token is Token {
    uint256 constant private MAX_UINT256 = 2**256 - 1;
    mapping (address => uint256) public balances;
    mapping (address => mapping (address => uint256)) public allowed;
    uint256 public totalSupply;
    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show.
    string public symbol;                 //An identifier: eg SBX

    constructor() {
        balances[msg.sender] = 1000 * 10**18;               // Give the creator all initial tokens
        totalSupply = 1000 * 10**18;                        // Update total supply
        name = "Custom Coin";                                   // Set the name for display purposes
        decimals = 18;                            // Amount of decimals for display purposes
        symbol = "CCN";                               // Set the symbol for display purposes
    }

    function transfer(address _to, uint256 _value) public override returns (bool success) {
        require(balances[msg.sender] >= _value, "token balance is lower than the value requested");
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) {
        uint256 allowanceValue = allowed[_from][msg.sender];
        require(balances[_from] >= _value && allowanceValue >= _value, "token balance or allowance is lower than amount requested");
        balances[_to] += _value;
        balances[_from] -= _value;
        if (allowanceValue < MAX_UINT256) {
            allowed[_from][msg.sender] -= _value;
        }
        emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function balanceOf(address _owner) public override view returns (uint256 balance) {
        return balances[_owner];
    }

    function approve(address _spender, uint256 _value) public override returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function allowance(address _owner, address _spender) public override view returns (uint256 remaining) {
        return allowed[_owner][_spender];
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市乃摹,隨后出現(xiàn)的幾起案子禁漓,更是在濱河造成了極大的恐慌,老刑警劉巖孵睬,帶你破解...
    沈念sama閱讀 216,402評(píng)論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件播歼,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡掰读,警方通過查閱死者的電腦和手機(jī)秘狞,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來磷支,“玉大人谒撼,你說我怎么就攤上這事∥肀罚” “怎么了廓潜?”我有些...
    開封第一講書人閱讀 162,483評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長善榛。 經(jīng)常有香客問我辩蛋,道長,這世上最難降的妖魔是什么移盆? 我笑而不...
    開封第一講書人閱讀 58,165評(píng)論 1 292
  • 正文 為了忘掉前任悼院,我火速辦了婚禮,結(jié)果婚禮上咒循,老公的妹妹穿的比我還像新娘据途。我一直安慰自己,他們只是感情好叙甸,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,176評(píng)論 6 388
  • 文/花漫 我一把揭開白布颖医。 她就那樣靜靜地躺著,像睡著了一般裆蒸。 火紅的嫁衣襯著肌膚如雪熔萧。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,146評(píng)論 1 297
  • 那天,我揣著相機(jī)與錄音佛致,去河邊找鬼贮缕。 笑死,一個(gè)胖子當(dāng)著我的面吹牛俺榆,可吹牛的內(nèi)容都是我干的感昼。 我是一名探鬼主播,決...
    沈念sama閱讀 40,032評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼肋演,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼抑诸!你這毒婦竟也來了烂琴?” 一聲冷哼從身側(cè)響起爹殊,我...
    開封第一講書人閱讀 38,896評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎奸绷,沒想到半個(gè)月后梗夸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,311評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡号醉,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,536評(píng)論 2 332
  • 正文 我和宋清朗相戀三年反症,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片畔派。...
    茶點(diǎn)故事閱讀 39,696評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡铅碍,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出线椰,到底是詐尸還是另有隱情胞谈,我是刑警寧澤,帶...
    沈念sama閱讀 35,413評(píng)論 5 343
  • 正文 年R本政府宣布憨愉,位于F島的核電站烦绳,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏配紫。R本人自食惡果不足惜径密,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,008評(píng)論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望躺孝。 院中可真熱鬧享扔,春花似錦、人聲如沸植袍。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽奋单。三九已至锉试,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背呆盖。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評(píng)論 1 269
  • 我被黑心中介騙來泰國打工拖云, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人应又。 一個(gè)月前我還...
    沈念sama閱讀 47,698評(píng)論 2 368
  • 正文 我出身青樓宙项,卻偏偏與公主長得像,于是被迫代替她去往敵國和親株扛。 傳聞我的和親對(duì)象是個(gè)殘疾皇子尤筐,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,592評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容