写点什么

智能合约 DAPP 项目系统开发技术逻辑(dEOM)

作者:I8O28578624
  • 2023-01-29
    广东
  • 本文字数:3123 字

    阅读完需:约 10 分钟

智能合约DAPP项目系统开发技术逻辑(dEOM)

任何程序员学习一个新的编程语言,一个最重要的仪式就是写出一个能输出 Hello World!的程序。完成后,这才算打开一个新世界的大门。本文主要介绍如何使用智能合约输出一个 Hello World!。本文的步骤说明十分简单(但步骤完整),大家如果想要看详细的步骤说明,请参考智能合约编写实例这篇文章,里面的实例描述更加详细。wei+StPv888

打开测试网络的控制台

输入以下命令:

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

这样我们就打开了测试网的控制台,之后的步骤如无特别说明都将在控制台中完成。

编写智能合约

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

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

编译智能合约

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

指定创建合约的外部账户

我们首先需要从当前的账户里选择一个作为创建智能合约的外部账户:

> address = eth.accounts[0]

"0x62b1746767522b36f6421e630fa0198151d72964"

然后将该账户激活:

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

true

最后开启挖矿,为处理交易做准备:

> miner.start()

true

部署合约

部署合约就是将编译好的合约字节码通过外部账号发送交易的形式部署到以太坊区块链上。输入以下命令:

> 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"

}

这时,我们可以检查一下交易池,查看当前交易的待处理状况:

> txpool.status

{

pending: 1,

queued: 0

}

耐心等待一段时间,等待矿工确认完成后,我们再次使用 txpool.status 命令查看交易池的状态:

> txpool.status

{

pending: 0,

queued: 0

}

这就说明该条交易已经成功被处理了。

与合约交互

首先我们需要使用 eth.contract 来定义一个合约类,定义的合约类遵从 ABI 定义 1:

> Hello = eth.contract(contract.info.abiDefinition)

{

abi: [{

constant: false,

inputs: [],

name: "hello",

outputs: [{...}],

payable: false,

type: "function"

}],

eth: {

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

blockNumber: 623,

coinbase: "0x62b1746767522b36f6421e630fa0198151d72964",

compile: {

lll: function(),

serpent: function(),

solidity: function()

},

defaultAccount: "0x62b1746767522b36f6421e630fa0198151d72964",

defaultBlock: "latest",

gasPrice: 20000000000,

hashrate: 3158,

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()

}

然后得到合约实例:

> hello = Hello.at(myContract.address)

{

abi: [{

constant: false,

inputs: [],

name: "hello",

outputs: [{...}],

payable: false,

type: "function"

}],

address: "0x67392c276e261d916243b7ba200d2c005d35ae57",

transactionHash: null,

allEvents: function(),

hello: function()

}

使用 call()调用:

> hello.hello.call()

"hello world!"

类似伊对视频相亲交友系统开发都有哪些功能?是什么样的盈利模式?

视频相亲盈利点:

1,添加好友,需要送礼物给对方。对方获得收益

2,直播相亲过程中,如需上麦,需要付费申请上麦。红娘获得收益

3,房间游客可以给麦上的嘉宾送礼物,嘉宾获得收益

4,麦上嘉宾可以给其他麦位的嘉宾和红娘送礼物,对方获得相应收益

5,直播间抢红包。

6,开通守护

7,分享赚钱,邀请好友,获得收益。

用户头像

I8O28578624

关注

还未添加个人签名 2022-05-13 加入

还未添加个人简介

评论

发布
暂无评论
智能合约DAPP项目系统开发技术逻辑(dEOM)_I8O28578624_InfoQ写作社区