Biyuan Project warehouse:

Github address: github.com/Bytom/bytom

Gitee address: gitee.com/BytomBlockc…

I. Brief description of the contract

Equity is a smart contract language of BYTom, which is a declarative predicate language. Please refer to the official equity contract for details.

Second, lock contract process

1. Contract writing

Contract writing can be structured by referring to the contract template. For further information, read the contract documentation. Take a typical locked PublicKey contract as an example. The contract code is as follows:

contract LockWithPublicKey(publicKey: PublicKey) locks locked { clause unlockWithSig(sig: Signature) { verify checkTxSig(publicKey, sig) unlock locked } }

2. Compile the contract

The tool for compiling contracts is not available yet. It is recommended to use API calls to compile contracts. You can use the curl command line or the Postman tool.

Curl is invoked as follows:

curl -X POST http://localhost:9888/create-key -d '{"alias": "alice", "password": "123456"}'

Postman needs to download the tools from the official website:

www.getpostman.com/

Bytomd enables auTH authentication by default. You need to curl the API interface to obtain access toekn

curl -X POST http://localhost:9888/create-access-token -d '{"id":"token1"}'

The result is as follows:

{ "token": "token1:1fee70f537128a201338bd5f25a3adbf33dad02eae4f4c9ac43f336a069df8f3", "id": "token1", "created_at": "The 2018-03-20 T18:56:01. 043919771 + 08:00"}

2) Select basic Auth authentication and enter the user name and password of Access-Token. The aforementioned token1 and 1 fee70f537128a201338bd5f25a3adbf33dad02eae4f4c9ac43f336a069df8f3 returns the result

3) If the contract parameter contains PublicKey, obtain PublicKey. PublicKey can be obtained through the API interface. Save the result and use the derivation_path corresponding to root_xpub and pubkey to unlock the contract.

4) Compile the contract, return the result program is the lockable contract. (Direct compilation of contracts produces contract execution steps. If such contracts are deployed, users can directly construct corresponding parameters to unlock them.)

3. Build lock-in contracts

Below said locking 1000 777 e3586d2ec47c4974d262e0ff86fd3c1c063d242d32bdef71d6d16eed6763e types of assets to the contract 204 e925f0fcc2f2618d96b7a3dce2aad28e60ab3339377760d48aea8ae8169ae417403ae7cac00c0. Refer to the wiki for building transactions: github.com/Bytom/bytom…

4. Signature transaction

Refer to the signature trading wiki: github.com/Bytom/bytom…

5. Submit a deal

For details, please refer to the wiki for submitting transactions: github.com/Bytom/bytom…

Once the contract transaction is packaged, the contract transaction is sent.

Iii. Contract unlocking process

1. After the contract transaction is successfully packaged by block, you can view the specific contract transaction content and find the corresponding outputID.

The ID field represents outputID

Outputs interface API to find the UTXO of the contract according to outputID and check whether the asset type and quantity locked by the contract match

The unlocking clause unlockWithSig parameter is Signature, but the Signature result can only be obtained after the success of sign-transaction, so we only need to build the Signature parameter. In April before constructing publicKey for e925f0fcc2f2618d96b7a3dce2aad28e60ab3339377760d48aea8ae8169ae41, then signature parameters for root_xpub and derivation_path, The corresponding values are: “dc903a862a14966d47dc6bc935c687c6cccb7a8f9c70f13bb82a41a0fe2696596cb141ff1840f90c75f8f25099f0dc50e005e1e36817d184b2b1eb 1354B61575 “and [“010400000000000000”, “0100000000000000”]. Its structure is as follows :(refer to the official smart contract documentation for specific fields)

4. Signature transaction, refer to signature transaction wiki: github.com/Bytom/bytom…

5, submit the transaction, refer to submit the transaction wiki: github.com/Bytom/bytom…

Outputs interface API to find the original CONTRACT UTXO according to outputID, will be displayed as empty, otherwise the contract transaction will fail to unlock.