Skip to content

Commit

Permalink
Deploying to gh-pages from @ 2b9bc21 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan1844 committed Nov 29, 2024
1 parent 94faa08 commit b68ebf6
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 615 deletions.
120 changes: 7 additions & 113 deletions contracts/compiler/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,7 @@
</li>
<li class="toctree-l3"><a class="reference internal" href="#4-trongrid">4. TronGrid</a>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_3">使用命令行工具进行智能合约开发</a>
<ul>
<li class="toctree-l3"><a class="reference internal" href="#_4">启动私有链</a>
</li>
<li class="toctree-l3"><a class="reference internal" href="#_5">开发智能合约</a>
</li>
<li class="toctree-l3"><a class="reference internal" href="#simplewebcompilerabibytecode">在SimpleWebCompiler编译得到ABI和ByteCode</a>
</li>
<li class="toctree-l3"><a class="reference internal" href="#wallet-cli">通过Wallet-cli部署智能合约</a>
<li class="toctree-l3"><a class="reference internal" href="#5-trident-java">5. Trident-java</a>
</li>
</ul>
</li>
Expand Down Expand Up @@ -193,111 +183,15 @@ <h3 id="1-tronide">1. TronIDE<a class="headerlink" href="#1-tronide" title="Perm
<a href="http://www.tronide.io/">http://www.tronide.io/</a></p>
<h3 id="2-tronbox">2. TronBox<a class="headerlink" href="#2-tronbox" title="Permanent link">&para;</a></h3>
<p>波场智能合约部署工具。支持solidity语言智能合约的编译,部署,移植等功能。
<a href="https://cn.developers.tron.network/reference/tronbox-%E7%AE%80%E4%BB%8B">https://cn.developers.tron.network/reference/tronbox-%E7%AE%80%E4%BB%8B</a></p>
<a href="https://developers.tron.network/reference/what-is-tronbox">https://developers.tron.network/reference/what-is-tronbox</a></p>
<h3 id="3-tronweb">3. TronWeb<a class="headerlink" href="#3-tronweb" title="Permanent link">&para;</a></h3>
<p>波场智能合约开发使用的http api库。提供和主链交互,合约部署调用等接口。
<a href="https://cn.developers.tron.network/docs/dapp-development-tools-tronweb">https://cn.developers.tron.network/docs/dapp-development-tools-tronweb</a></p>
<p>波场智能合约开发使用的javascript库。提供和主链交互,合约部署调用等接口。
<a href="https://tronweb.network/docu/docs/intro/">https://tronweb.network/docu/docs/intro/</a></p>
<h3 id="4-trongrid">4. TronGrid<a class="headerlink" href="#4-trongrid" title="Permanent link">&para;</a></h3>
<p>波场智能合约事件查询服务。可以查询智能合约中写入的事件log信息。
<a href="https://cn.developers.tron.network/docs/trongrid">https://cn.developers.tron.network/docs/trongrid</a></p>
<h2 id="_3">使用命令行工具进行智能合约开发<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h2>
<p>在tron上进行智能合约的开发,除了使用现有的工具(tron-studio)之外,也可以直接使用wallet-cli命令行工具进行智能合约的开发,编译和部署。编写智能合约,可以使用使用TronStudio进行编译、调试等前期的开发工作。 当合约开发完成之后,可以把合约复制到<a href="https://github.com/tronprotocol/tron-demo/tree/master/SmartContractTools/SimpleWebCompiler">SimpleWebCompiler</a>中进行编译,获取ABI和ByteCode。</p>
<p>我们提供一个简单的数据存取的合约代码示例,以这个示例来说明编译、部署、调用的步骤。</p>
<div class="highlight"><pre><span></span><code>pragma solidity ^0.4.0;
contract DataStore {

mapping(uint256 =&gt; uint256) data;

function set(uint256 key, uint256 value) public {
data[key] = value;
}

function get(uint256 key) view public returns (uint256 value) {
value = data[key];
}
}
</code></pre></div>
<h3 id="_4">启动私有链<a class="headerlink" href="#_4" title="Permanent link">&para;</a></h3>
<p>确保前提条件中,私有链已经在本地部署完成。可以检查FullNode/logs/tron.log中,是否有持续产块的log信息出现:“Produce block successfully”</p>
<h3 id="_5">开发智能合约<a class="headerlink" href="#_5" title="Permanent link">&para;</a></h3>
<p>把上述代码复制到remix中编译,调试,确保代码的逻辑是自己需要的,编译通过,没有错误</p>
<h3 id="simplewebcompilerabibytecode">在SimpleWebCompiler编译得到ABI和ByteCode<a class="headerlink" href="#simplewebcompilerabibytecode" title="Permanent link">&para;</a></h3>
<p>因为波场的编译器与以太坊的编译略有差异,正在与Remix集成中,所以临时采用改方案获取ABI和ByteCode,而不是通过Remix直接获取ABI和ByteCode。
把上述代码复制到SimpleWebCompiler中,点击Compile按钮,获取ABI和ByteCode。</p>
<h3 id="wallet-cli">通过Wallet-cli部署智能合约<a class="headerlink" href="#wallet-cli" title="Permanent link">&para;</a></h3>
<p>下载Wallet-Cli,文件然后编译。</p>
<div class="highlight"><pre><span></span><code><span class="c1"># 下载源代码</span>
git<span class="w"> </span>clone<span class="w"> </span>https://github.com/tronprotocol/wallet-cli
<span class="nb">cd</span><span class="w"> </span>wallet-cli
<span class="c1"># 编译</span>
./gradlew<span class="w"> </span>build
<span class="nb">cd</span><span class="w"> </span>build/libs
</code></pre></div>
<p>注意:
wallet-cli 默认的配置会连接本地127.0.0.1:50051的 fullnode,如果开发者需要连接不同的其他节点或者端口可在 config.conf 文件中进行修改</p>
<p>启动wallet-cli</p>
<div class="highlight"><pre><span></span><code>java -jar wallet-cli.jar
</code></pre></div>
<p>启动之后,可在命令中交互式输入指令。导入私钥,并查询余额是否正确</p>
<div class="highlight"><pre><span></span><code>importwallet
&lt;输入你自己的设定的钱包密码2次&gt;
&lt;输入私钥:da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0&gt;
login
&lt;输入你自己的设定的钱包密码&gt;
getbalance
</code></pre></div>
<p>部署合约</p>
<div class="highlight"><pre><span></span><code># 合约部署指令
DeployContract contractName ABI byteCode constructor params isHex fee_limit consume_user_resource_percent &lt;value&gt; &lt;library:address,library:address,...&gt;

# 参数说明
contract_name:自己制定的合约名
ABI:从SimpleWebCompiler中获取到的 ABI json 数据
bytecode:从SimpleWebCompiler中获取到的二进制代码
constructor:部署合约时,会调用构造函数,如果需要调用,就把构造函数的参数类型填写到这里,例如:constructor(uint256,string),如果没有,就填写一个字符#
params:构造函数的参数,使用逗号分隔开来,例如 1,&quot;test&quot; ,如果没有构造函数,就填写一个字符#
fee_limit:本次部署合约消耗的TRX的上限,单位是SUN(1 SUN = 10^-6 TRX),包括CPU资源、STORAGE资源和可用余额的消耗
consume_user_resource_percent:指定的使用该合约用户的资源占比,是[0, 100]之间的整数。如果是0,则表示用户不会消耗资源。如果开发者资源消耗完了,才会完全使用用户的资源。
value:在部署合约时,给该合约转账金额,使用十六进制32位表示
library:address,library:address,...:如果合约包含library,则需要在部署合约的时候指定library的地址,具体见下文;没有library的话则不需要填写。

# 运行例子
deploycontract DataStore [{&quot;constant&quot;:false,&quot;inputs&quot;:[{&quot;name&quot;:&quot;key&quot;,&quot;type&quot;:&quot;uint256&quot;},{&quot;name&quot;:&quot;value&quot;,&quot;type&quot;:&quot;uint256&quot;}],&quot;name&quot;:&quot;set&quot;,&quot;outputs&quot;:[],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;nonpayable&quot;,&quot;type&quot;:&quot;function&quot;},{&quot;constant&quot;:true,&quot;inputs&quot;:[{&quot;name&quot;:&quot;key&quot;,&quot;type&quot;:&quot;uint256&quot;}],&quot;name&quot;:&quot;get&quot;,&quot;outputs&quot;:[{&quot;name&quot;:&quot;value&quot;,&quot;type&quot;:&quot;uint256&quot;}],&quot;payable&quot;:false,&quot;stateMutability&quot;:&quot;view&quot;,&quot;type&quot;:&quot;function&quot;}] 608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029 # # false 1000000 30 0
部署成功会显示Deploy the contract successfully
</code></pre></div>
<p>得到合约的地址</p>
<div class="highlight"><pre><span></span><code>Your smart contract address will be: &lt;合约地址&gt;

# 在本例中
Your smart contract address will be: TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6
</code></pre></div>
<p>调用合约存储数据、查询数据</p>
<div class="highlight"><pre><span></span><code>Shell
# 调用合约指令
triggercontract &lt;contract_address&gt; &lt;method&gt; &lt;args&gt; &lt;is_hex&gt; &lt;fee_limit&gt; &lt;value&gt;

# 参数说明
contract_address:即之前部署过合约的地址,格式 base58,如:TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6
method:调用的函数签名,如set(uint256,uint256)或者 fool(),参数使用&#39;,&#39;分割且不能有空格
args:如果非十六进制,则自然输入使用&#39;,&#39;分割且不能有空格,如果是十六进制,直接填入即可
is_hex:输入参数是否为十六进制,false 或者 true
fee_limit:和deploycontract的时候类似,表示本次部署合约消耗的TRX的上限,单位是SUN(1 SUN = 10^-6 TRX),包括CPU资源、STORAGE资源和可用余额的消耗。
value:在部署合约时,给该合约转账金额,使用十六进制32位表示

# 调用的例子
## 设置 mapping 1-&gt;1
triggercontract TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6 set(uint256,uint256) 1,1 false 1000000 0000000000000000000000000000000000000000000000000000000000000000

## 取出 mapping key = 1的 value
triggercontract TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6 get(uint256) 1 false 1000000 0000000000000000000000000000000000000000000000000000000000000000
</code></pre></div>
<p>如果调用的函数是 constant 或 view,wallet-cli 将会直接返回结果</p>
<p>如果包含library,则需要在部署合约之前先部署library,部署完library之后,知道了library地址,将地址填进library:address,library:address,...</p>
<div class="highlight"><pre><span></span><code># 比如使用remix生成的合约,bytecode是
608060405234801561001057600080fd5b5061013f806100206000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063f75dac5a14610046575b600080fd5b34801561005257600080fd5b5061005b610071565b6040518082815260200191505060405180910390f35b600073&lt;b&gt;__browser/oneLibrary.sol.Math3__________&lt;\b&gt;634f2be91f6040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b1580156100d357600080fd5b505af41580156100e7573d6000803e3d6000fd5b505050506040513d60208110156100fd57600080fd5b81019080805190602001909291905050509050905600a165627a7a7230582052333e136f236d95e9d0b59c4490a39e25dd3a3dcdc16285820ee0a7508eb8690029
</code></pre></div>
<p>之前部署的library地址是:TSEJ29gnBkxQZR3oDdLdeQtQQykpVLSk54
那么部署的时候,需要将 browser/oneLibrary.sol.Math3:TSEJ29gnBkxQZR3oDdLdeQtQQykpVLSk54 作为deploycontract的参数。</p>
<a href="https://developers.tron.network/docs/trongrid">https://developers.tron.network/docs/trongrid</a></p>
<h3 id="5-trident-java">5. Trident-java<a class="headerlink" href="#5-trident-java" title="Permanent link">&para;</a></h3>
<p>trident-java是一个极其轻量的JAVA SDK。它包含了一系列库,方便开发者使用波场网络的系统与智能合约。</p>

</div>
</div><footer>
Expand Down
21 changes: 6 additions & 15 deletions contracts/contract/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
<h1 id="_1">智能合约<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h1>
<h2 id="_2">波场智能合约介绍<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h2>
<p>智能合约是一种能自动执行其条款的计算化交易协议。智能合约和普通合约一样,定义了参与者相关的条款和奖惩机制。一旦合约被启动,便能按照设定的条款执行,并自动检查所承诺的条款实施情形。
Tron兼容以太坊(Ethereum)上采用Solidity编写的智能合约。当前建议的Solidity语言版本为0.4.24 ~ 0.4.25。合约编写、编译完成后,部署到Tron公链上。部署后的合约,被触发时,就会在公链的各个节点上自动执行。</p>
Tron兼容以太坊(Ethereum)上采用Solidity编写的智能合约。你可以在<a href="https://github.com/tronprotocol/solidity/releases">Tron solidity 代码库</a>中了解最新的版本。合约编写、编译完成后,部署到Tron公链上。部署后的合约,被触发时,就会在公链的各个节点上自动执行。</p>
<h2 id="_3">波场智能合约特性<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h2>
<p>Tron virtual machine 基于以太坊 solidity 语言实现,兼容以太坊虚拟机的特性,但基于tron自身属性也有部分的区别。</p>
<h3 id="1">1. 智能合约<a class="headerlink" href="#1" title="Permanent link">&para;</a></h3>
Expand Down Expand Up @@ -271,7 +271,7 @@ <h3 id="2">2. 合约函数的使用<a class="headerlink" href="#2" title="Perman
</ul>
<p>另一个与合约调用相关的是调用指令集的时候使用CREATE指令。这个指令将会创建一个新的合约并生成新的地址。与以太坊的创建唯一的不同在于波场新生成的地址使用的是传入的本次智能合约交易id与调用的nonce的哈希组合。和以太坊不同,这个nonce的定义为本次根调用开始创建的合约序号。即如果有多次的 CREATE指令调用,从1开始,顺序编号每次调用的合约。详细请参考代码。还需注意,与deploycontract的grpc调用创建合约不同,CREATE的合约并不会保存合约的abi。</p>
<ul>
<li>内置功能属性及内置函数 (Odyssey-v3.1.1及之后的版本暂时不支持TVM内置函数)</li>
<li>内置功能</li>
</ul>
<div class="highlight"><pre><span></span><code><span class="m">1</span>)TVM兼容solidity语言的转账形式,包括:
伴随constructor调用转账
Expand All @@ -280,20 +280,11 @@ <h3 id="2">2. 合约函数的使用<a class="headerlink" href="#2" title="Perman

注意,波场的智能合约与波场系统合约的逻辑不同,如果转账的目标地址账户不存在,不能通过智能合约转账的形式创建目标地址账户。这也是与以太坊的不同点。

<span class="m">2</span>)不同账户为超级节点投票<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">3</span>)超级节点获取所有奖励<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">4</span>)超级节点通过或否定提案<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">5</span>)超级节点提出提案<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">6</span>)超级节点删除提案<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">7</span>)波场byte地址转换为solidity地址<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">8</span>)波场string地址转换为solidity地址<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">9</span>)向目标账户地址发送token转账<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">10</span>)查询目标账户地址的指定token的数量<span class="w"> </span><span class="o">(</span>Odyssey-v3.1.1及之后的版本暂时不支持<span class="o">)</span>
<span class="m">11</span>)兼容所有以太坊内置函数
<span class="m">2</span>)为超级节点投票<span class="w"> </span>
<span class="m">3</span>)质押
<span class="m">4</span>)资源代理
<span class="m">5</span>)兼容所有以太坊内置函数
</code></pre></div>
<p>注意:
波场2)- 10)为波场自己的内置函数 具体中文文档请参看:https://github.com/tronprotocol/Documentation/blob/master/中文文档/虚拟机/虚拟机内置函数.md</p>
<p>以太坊 RIPEMD160 函数不推荐使用,波场返回的是一个自己的基于sha256的hash结果,并不是准确的以太坊RIPEMD160。以后会考虑删除这个函数。</p>
<h3 id="3-solidity">3. 合约地址在solidity语言的使用<a class="headerlink" href="#3-solidity" title="Permanent link">&para;</a></h3>
<p>以太坊虚拟机地址为是20字节,而波场虚拟机解析地址为21字节。
* 地址转换</p>
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,5 @@ <h1 id="java-tron">欢迎访问Java-tron用户手册!<a class="headerlink" href=

<!--
MkDocs version : 1.3.0
Build Date UTC : 2024-11-23 06:51:45.809320+00:00
Build Date UTC : 2024-11-29 11:12:12.318961+00:00
-->
Loading

0 comments on commit b68ebf6

Please sign in to comment.