關於牧場世界遊戲系統開發成熟技術(Demo)

a1271916008發表於2023-04-26

開啟測試網路的控制檯

輸入以下命令:


geth --datadir "~/ethdev" --dev console 2>> geth.log

1

這樣我們就開啟了測試網的控制檯,之後的步驟如無特別說明都將在控制檯中完成。


編寫智慧合約

> source = "contract test { function hello() returns(string s){return 'hello world!';}}"

"contract test { function hello() returns(string s){return 'hello world!';}}"

1

2

編譯智慧合約

> contract = eth.compile.solidity(source).test

1

指定建立合約的外部賬戶

我們首先需要從當前的賬戶裡選擇一個作為建立智慧合約的外部賬戶:


> address = eth.accounts[0]

"0x62b1746767522b36f6421e630fa0198151d72964"

1

2

然後將該賬戶啟用:


> personal.unlockAccount(address,'123456',10000)

true

1

2

最後開啟挖礦,為處理交易做準備:


> miner.start()

true

1

2

部署合約

部署合約就是將編譯好的合約位元組碼透過外部賬號傳送交易的形式部署到以太坊區塊鏈上。輸入以下命令:


> abi = [{constant:false,inputs:null}]

[{

    constant: false,

    inputs: null

}]

> MyContract = eth.contract(abi)

{

  abi: [{

      constant: false,

      inputs: null

  }],

  eth: {

    accounts: ["0x62b1746767522b36f6421e630fa0198151d72964", "0xaa79b5468a4f4cf35a32cc976f689a5db5873f0c"],

    blockNumber: 600,

    coinbase: "0x62b1746767522b36f6421e630fa0198151d72964",

    compile: {

      lll: function(),

      serpent: function(),

      solidity: function()

    },

    defaultAccount: "0x62b1746767522b36f6421e630fa0198151d72964",

    defaultBlock: "latest",

    gasPrice: 20000000000,

    hashrate: 3302,

    mining: true,

    pendingTransactions: [],

    syncing: false,

    call: function(),

    contract: function(abi),

    estimateGas: function(),

    filter: function(fil, callback),

    getAccounts: function(callback),

    getBalance: function(),

    getBlock: function(),

    getBlockNumber: function(callback),

    getBlockTransactionCount: function(),

    getBlockUncleCount: function(),

    getCode: function(),

    getCoinbase: function(callback),

    getCompilers: function(),

    getGasPrice: function(callback),

    getHashrate: function(callback),

    getMining: function(callback),

    getNatSpec: function(),

    getPendingTransactions: function(callback),

    getStorageAt: function(),

    getSyncing: function(callback),

    getTransaction: function(),

    getTransactionCount: function(),

    getTransactionFromBlock: function(),

    getTransactionReceipt: function(),

    getUncle: function(),

    getWork: function(),

    iban: function(iban),

    icapNamereg: function(),

    isSyncing: function(callback),

    namereg: function(),

    resend: function(),

    sendIBANTransaction: function(),

    sendRawTransaction: function(),

    sendTransaction: function(),

    sign: function(),

    signTransaction: function(),

    submitTransaction: function(),

    submitWork: function()

  },

  at: function(address, callback),

  getData: function(),

  new: function()

}


> myContract = MyContract.new({from:address,data:contract.code})

{

  abi: [{

      constant: false,

      inputs: null

  }],

  address: undefined,

  transactionHash: "0x9f0f739a5827796fc1466a09e7771eef0978262a007f8c75c789cdcf1d9c3d4b"

}


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

相關文章