Skip to content

Commit

Permalink
Merge pull request #397 from vivian1912/master
Browse files Browse the repository at this point in the history
new release 4.7.7
  • Loading branch information
ethan1844 authored Nov 29, 2024
2 parents 20e4c27 + 8353ae4 commit a0a80b0
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 244 deletions.
137 changes: 4 additions & 133 deletions docs/contracts/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,141 +13,12 @@ Support the build, deploy, transplant, etc. for solidity language written smart
[https://developers.tron.network/reference/what-is-tronbox](https://developers.tron.network/reference/what-is-tronbox)

<h3> 3. TronWeb </h3>
Provide http api service for the usage of smart contract.
[https://developers.tron.network/docs/tronweb-1](https://developers.tron.network/docs/tronweb-1)
Provide javascript api for the usage of smart contract.
[https://tronweb.network/docu/docs/intro/](https://tronweb.network/docu/docs/intro/)

<h3> 4. TronGrid </h3>
Provide smart contract event query service.
[https://developers.tron.network/docs/trongrid](https://developers.tron.network/docs/trongrid)

## Development

First you can use TronStudio to write, build and debug the smart contract. After you finish the development of the contract, you can copy it to [SimpleWebCompiler](https://github.com/tronprotocol/tron-demo/tree/master/SmartContractTools/SimpleWebCompiler) to compile to get ABI and ByteCode. We provide a simple data read/write smart contract code example to demonstrate:

```text
pragma solidity ^0.4.0;
contract DataStore {
mapping(uint256 => uint256) data;
function set(uint256 key, uint256 value) public {
data[key] = value;
}
function get(uint256 key) view public returns (uint256 value) {
value = data[key];
}
}
```

** Start a Private Net **

Make sure the fullnode code has been deployed locally, you can check if 'Produce block successfully' log appears in FullNode/logs/tron.log

** Develop a Smart Contract **

Copy the code example above to remix to debug.

** Compile in SimpleWebCompiler for ABI and ByteCode **

Copy the code example above to SimpleWebCompiler to get ABI and ByteCode.
Because TRON's compiler is a little different from Ethereum, so you can not get ABI and ByteCode by using Remix. But it will soon be supported.

** Using Wallet-cli to Deploy **

Download Wallet-Cli and build

```text
shell
# download source code
git clone https://github.com/tronprotocol/wallet-cli
cd wallet-cli
# build
./gradlew build
cd build/libs
```

Note: You need to change the node ip and port in config.conf

start wallet-cli

```text
java -jar wallet-cli.jar
```

after started, you can use command lines to operate:

```text
importwallet
<input your password twice for your account>
<input your private key>
login
<input your password you set>
getbalance
```

deploy contract

```text
Shell
# contract deployment command
DeployContract contractName ABI byteCode constructor params isHex fee_limit consume_user_resource_percent <value> <library:address,library:address,...>
# parameters
contract_name: Contract name
ABI: ABI from SimpleWebCompiler
bytecode: ByteCode from SimpleWebCompiler
constructor: When deploy contract, this will be called. If is needed, write as constructor(uint256,string). If not, just write #
params: The parameters of the constructor, use ',' to split, like 1, "test", if no constructor, just write #
fee_limit: The TRX consumption limit for the deployment, unit is SUN(1 SUN = 10^-6 TRX)
consume_user_resource_percent: Consume user's resource percentage. It should be an integer between [0, 100]. if 0, means it does not consume user's resource until the developer's resource has been used up
value: The amount of TRX transfer to the contract when deploy
library: If the contract contains library, you need to specify the library address
# example
deploycontract DataStore [{"constant":false,"inputs":[{"name":"key","type":"uint256"},{"name":"value","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"key","type":"uint256"}],"name":"get","outputs":[{"name":"value","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] 608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029 # # false 1000000 30 0
If it is deployed successfully, it will return 'Deploy the contract successfully'
```

get the contract address

```text
Your smart contract address will be: <contract address>
# in this example
Your smart contract address will be: TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6
```

call the contract to store data, query data

```text
Shell
# call contract command
triggercontract <contract_address> <method> <args> <is_hex> <fee_limit> <value>
# parameters
contract_address: Contract address, like TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6
method: The method called, like set(uint256,uint256) or fool(), use ',' to split the parameters. Do not leave space between parameters
args: The parameters passed to the method called, use ',' to split the parameters. Do not leave space between parameters
is_hex: whether the input parameters is Hex, false or true
fee_limit: The TRX consumption limit for the trigger, unit is SUN(1 SUN = 10^-6 TRX)
value: The amount of TRX transfer to the contract when trigger
# trigger example
## set mapping 1->1
triggercontract TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6 set(uint256,uint256) 1,1 false 1000000 0000000000000000000000000000000000000000000000000000000000000000
## get mapping key = 1
triggercontract TTWq4vMEYB2yibAbPV7gQ4mrqTyX92fha6 get(uint256) 1 false 1000000 0000000000000000000000000000000000000000000000000000000000000000
```

If the function called is constant or view, wallet-cli will return the result directly.
If it contains library, before deploy the contract you need to deploy the library first. After you deploy library, you can get the library address, then fill the address in library:address,library:address,...

```text
# for instance, using remix to get the bytecode of the contract, like:
608060405234801561001057600080fd5b5061013f806100206000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063f75dac5a14610046575b600080fd5b34801561005257600080fd5b5061005b610071565b6040518082815260200191505060405180910390f35b600073<b>__browser/oneLibrary.sol.Math3__________<\b>634f2be91f6040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b1580156100d357600080fd5b505af41580156100e7573d6000803e3d6000fd5b505050506040513d60208110156100fd57600080fd5b81019080805190602001909291905050509050905600a165627a7a7230582052333e136f236d95e9d0b59c4490a39e25dd3a3dcdc16285820ee0a7508eb8690029
```

The address of the library deployed before is: TSEJ29gnBkxQZR3oDdLdeQtQQykpVLSk54
When you deploy, you need to use browser/oneLibrary.sol.Math3:TSEJ29gnBkxQZR3oDdLdeQtQQykpVLSk54 as the parameter of deploycontract.
<h3> 5. Trident-java </h3>
Trident-java is a lightweight SDK that includes libraries for working with TRON system contracts and smart contracts.
2 changes: 1 addition & 1 deletion docs/contracts/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Smart contract is a computerized transaction protocol that automatically implements its terms. Smart contract is the same as common contract, they all define the terms and rules related to the participants. Once the contract is started, it can runs in the way it is designed.

TRON smart contract support Solidity language in (Ethereum). Currently recommend Solidity language version is 0.4.24 ~ 0.4.25. Write a smart contract, then build the smart contract and deploy it to TRON network. When the smart contract is triggered, the corresponding function will be executed automatically.
TRON smart contract support Solidity language in (Ethereum). You can find the latest solidity version in the [Tron solidity repository](https://github.com/tronprotocol/solidity/releases). Write a smart contract, then build the smart contract and deploy it to TRON network. When the smart contract is triggered, the corresponding function will be executed automatically.

## Smart Contract Features
TRON virtual machine is based on Ethereum solidity language, it also has TRON's own features.
Expand Down
48 changes: 1 addition & 47 deletions docs/introduction/dpos.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,54 +81,8 @@ When a fork occurs, an honest witness would always choose to produce blocks on t
To ensure the safe and efficient operation of the blockchain system, TRON sets up an incentive model to encourage more nodes to join the network, thereby expanding the scale of the network. Every time a block is generated by the TRON network, a block reward of 16 TRX will be awarded to the super representative who produced the block, and a voting reward of 160 TRX will be awarded to all super representatives and super partners (super representative candidates who ranking 28th~ 127th are also called super partners), and they share the voting rewards proportionally according to the number of votes they get. At the same time, super representatives and partners will also deduct the rewards according to their commission ratio, and distribute the remaining part to voters according to the voter voting ratio.

## Proposal-based parameter adjustment
An important characteristic of DPoS is that any parameter adjustment can be proposed on the chain, and witnesses will decide whether to approve the proposal by starting a vote. The advantage of this method is that it avoids hard fork upgrades when adding new features. Currently, TRON supports the following parameter adjustments:
An important characteristic of DPoS is that any parameter adjustment can be proposed on the chain, and witnesses will decide whether to approve the proposal by starting a vote. The advantage of this method is that it avoids hard fork upgrades when adding new features. For the current dynamic parameters and values ​​of the TRON network, as well as past proposals, please refer to [here](https://tronscan.org/#/sr/committee).

1. The interval between two maintenance periods

2. The TRX cost of applying to be a bookkeeper candidate

3. The TRX cost of account activation

4. The bandwidth cost for one byte in each transaction

5. The TRX cost of issuing tokens on TRON

6. The rewards for producing each block

7. The total amount of TRX that is proportionately awarded to the first 127th witnesses (including bookkeeper candidates) with the most votes

8. The TRX cost of account activation through system contract

9. The bandwidth cost for account activation

10. The exchange rate between Energy and Sun

11. The TRX cost for building a TRC-10 token-based decentralized trading pair

12. The maximum CPU time allowed for a single transaction execution

13. Whether to allow changes of account names

14. Whether to allow the issuance of assets with duplicate names

15. Whether to allow resource delegation

16. The upper limit for Energy in TRON blockchain

17. Whether to allow TRC-10 asset transfer in smart contracts

18. Whether to allow adjustment to Energy upper limit

19. Whether to allow multi-signature

20. The TRX cost of updating account access

21. The TRX cost of multi-signature transactions

22. Whether to verify block and transaction protobuf message

## Bandwidth and energy mechanism
To be continued...

## Appendix: Reference Documentations

Expand Down
2 changes: 1 addition & 1 deletion docs/mechanism-algorithm/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

TRON uses account model. An account's identity is address. It needs private key signature to operate an account. An account has many attributes, like TRX balance, tokens balance, bandwidth, etc. TRX and tokens can be transferred from account to account and it costs bandwidth. An account can also issue a smart contract, apply to become a super representative candidate, vote, etc. All TRON's activities are based on account.
TRON uses the account model. The address is the unique identifier of an account, and a private key signature is required to operate an account. An account has many attributes, including TRX & TRC10 token balances, bandwidth, energy, Etc. An account can send transactions to increase or reduce its TRX or TRC10 token balances, deploy smart contracts, and trigger the smart contracts released by itself or others. All TRON accounts can apply to be Super Representatives or vote for the elected Super Representatives. Accounts are the basis of all activities on TRON.

## How to Create an Account

Expand Down
19 changes: 2 additions & 17 deletions docs/mechanism-algorithm/multi-signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

## Background

!!! note
**Since v3.5** In the past version, the transactions created in one account can only be signed by one private key, an account can only be managed by one private key. Since V3.5, an account can be managed by several private keys, and the transactions created in one account can be signed by serval private keys.
Multiple signature functions allow for permission grading, and each permission can correspond to multiple private keys. This makes it possible to achieve multi-person joint control of accounts. This guide walks the user through TRON's multi-signature implementation and design.

Reference: [TIP-16: Account Multi-signature](https://github.com/tronprotocol/TIPs/blob/master/tip-16.md)

Expand Down Expand Up @@ -58,7 +57,7 @@ message AccountPermissionUpdateContract {
- `witness`: Witness permission (if is witness)
- `actives`: Active permission

This will override the Original account permission.
This will override the Original account permission. Therefore, if you only want to modify the owner permission, witness (if it is a witnss account) and active permission also need to be set

#### Permission

Expand Down Expand Up @@ -305,17 +304,3 @@ Please refer to [HTTP API](../api/http.md) and [RPC API](../api/rpc.md) for more
rpc GetTransactionSignWeight (Transaction) returns (TransactionSignWeight) {}
```

## Others

Since V3.5, what is the change after a new account is created?

When to create a new account, an owner permission and active permission will be generated automatically. Owner permission only contains one key, the weight and threshold are both 1. Active permission also contains one key, the weight and threshold are both 1, and operations is "7fff1fc0033e0000000000000000000000000000000000000000000000000000", means it support the execution of all contracts except AccountPermissionUpdateContract.
After V3.5, if there is a new system contract, the default operations value of the newly created account will change. The operations of existing accounts will not change.

Please refer to [wallet-cli](https://github.com/tronprotocol/wallet-cli/blob/master/README.md) to check the usage of multi-signature.

## Fees

If you update your account permission, the fee is 100 TRX.

If a transaction is signed by more than 1 account, the fee is 1 TRX.
44 changes: 3 additions & 41 deletions docs/mechanism-algorithm/sr.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The final output above is: Vote 3 votes for witness1, 7 votes for witness2

### Witnesses Brokerage

The default ratio is 20%, which can be modified by the witnesses.
The default ratio is 20%. Super representatives and super representative partners can query the brokerage ratio through the `wallet/getBrokerage` interface, and can also modify the brokerage ratio through the `wallet/updateBrokerage` interface.

If a witness get 20% of the reward, and the other 80% will be awarded to the voters. If the brokerage ratio is set to 100%, the rewards are all obtained by the witness; if set to 0, the rewards are all sent to the voters.

Expand Down Expand Up @@ -70,54 +70,16 @@ Committee can modify the TRON network parameters, like transacton fees, block pr

Only SRs, Partners and Candidates can create a proposal.

The network parameters can be modified([min,max]).

{0,1}: 1 means 'allowed' or 'actived', 0 means 'disallow', 'disable' or 'no'.

| # | Command | Value |
| ---- | ---- | ---- |
| 0 | MaintenanceTimeInterval <br> (To modify the maintenance interval of SR) | 6 Hours <br> [3 * 27, 24 * 3600] s |
| 1 | AccountUpgradeCost <br> (To modify the cost of applying for SR account) | 9999 TRX <br> [0, 100000000000] TRX |
| 2 | CreateAccountFee <br> (To modify the account creation fee) | 0.1 TRX <br> [0, 100000000000] TRX |
| 3 | TransactionFee <br> (To modify the amount of TRX used to gain extra bandwidth) | 1000 Sun/Byte <br> [0, 100000000000] TRX |
| 4 | AssetIssueFee <br> (To modify asset issuance fee) | 1024 TRX <br> [0, 100000000000] TRX|
| 5 | WitnessPayPerBlock <br> (To modify SR block generation reward) | 16 TRX <br> [0, 100000000000] TRX |
| 6 | WitnessStandbyAllowance <br> (To modify the rewards given to the top 27 SRs and <br> the following 100 partners) | 115200 TRX <br> [0, 100000000000] TRX |
| 7 | CreateNewAccountFeeInSystemContract <br> (To modify the cost of account creation) | 1 TRX |
| 8 | CreateNewAccountBandwidthRate <br> (To modify the consumption of bandwidth of account creation) | 1&nbsp;Bandwidth/Byte |
| 9 | AllowCreationOfContracts <br> (To activate the Virtual Machine (VM)) | 1 <br> {0, 1} |
| 10 | RemoveThePowerOfTheGr <br> (To remove the GR Genesis votes) | 1 <br> {0, 1}|
| 11 | EnergyFee <br> (To modify the fee of 1 energy) | 140 Sun <br> [0, 100000000000] TRX |
| 12 | ExchangeCreateFee <br> (To modify the cost of trading pair creation) | 1024 TRX <br> [0, 100000000000] TRX |
| 13 | MaxCpuTimeOfOneTx <br> (To modify the maximum execution time of one transaction) | 50 ms <br> [0, 1000] ms |
| 14 | AllowUpdateAccountName <br> (To allow to change the account name) | 0 <br> {0, 1} |
| 15 | AllowSameTokenName <br> (To allow the same token name) | 1 <br> {0, 1} |
| 16 | AllowDelegateResource <br> (To allow resource delegation) | 1 <br> {0, 1} |
| 18 | AllowTvmTransferTrc10 <br> (To allow the TRC-10 token transfer in smart contracts) | 1 <br> {0, 1} |
| 19 | TotalEnergyCurrentLimit <br> (To modify current total energy limit) | 50000000000 |
| 20 | AllowMultiSign <br> (To allow the initiation of multi-signature) | 1 <br> {0, 1} |
| 21 | AllowAdaptiveEnergy <br> (To allow adaptive adjustment for total Energy) | 0 <br> {0, 1} |
| 22 | UpdateAccountPermissionFee <br> (To modify the fee for updating account permission) | 100 TRX |
| 23 | MultiSignFee <br> (To modify the fee for multi-signature) | 1 TRX |
| 24 | AllowProtoFilterNum <br> (To enable protocol optimization) | 0 <br> {0, 1} |
| 26 | AllowTvmConstantinople <br> (To support the new commands of Constantinople) | 1 <br> {0, 1} |
| 27 | AllowShieldedTransaction <br> (To enable shielded transaction) | 0 <br> {0, 1} |
| 28 | ShieldedTransactionFee <br> (To modify shielded transaction fee) | 10 TRX <br> [0, 10000] TRX |
| 29 | AdaptiveResourceLimitMultiplier <br> (To modify the adaptive energy limit multiplier) | 1000 <br> [1, 10000] |
| 30 | ChangeDelegation <br> (Propose to support the decentralized vote dividend) | 1 <br> {0, 1} |
| 31 | Witness127PayPerBlock <br> (Propose to modify the block voting rewards given to <br> the top 27 SRs and the following 100 partners) | 160 TRX <br> [0, 100000000000] TRX |
| 32 | AllowTvmSolidity059 <br> (To allow TVM to support solidity compiler 0.5.9) | 0 <br> {0, 1} |
| 33 | AdaptiveResourceLimitTargetRatio <br> (To modify the target energy limit) | 10 <br> [1, 1000] |
Please refer to [here](https://tronscan.org/#/sr/committee) for TRON network dynamic parameters and their values.

Example (Using wallet-cli):

```console
> createproposal id value
# id: the serial number (0 ~ 33)
# id: the serial number
# value: the parameter value
```

Note: In TRON network, 1 TRX = 1_000_000 SUN

### 3. Vote for a Proposal

Expand Down
Loading

0 comments on commit a0a80b0

Please sign in to comment.