Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compile publickey contracts

2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to compile publickey contracts", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to compile publickey contracts.

I. brief introduction of the contract

Equity is an intelligent contract language of bytom and a declarative predicate language. For more information, please refer to the introduction of the official equity contract.

Second, lock the contract process 1. Contract preparation

The writing of the contract can be constructed by referring to the contract template, and if you need to know more, you can read the documentation related to the contract. 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. Compilation contract

Tools for compiling contracts are not available, so it is recommended to use api calls to compile contracts. You can call it using the curl command line or the postman tool.

The method of calling curl is as follows:

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

Postman needs to download tools from the official website:

Https://www.getpostman.com/

1) bytomd enables or enables auth authentication by default, and you need to call API API to obtain access toekn through curl.

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

The returned result is as follows:

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

2) Select basic auth authentication method, and enter the user name and password of access-token, that is, the token1 and 1fee70f537128a201338bd5f25a3adbf33dad02eae4f4c9ac43f336a069df8f3 of the result returned above.

3) if the contract parameter contains type PublicKey, you need to obtain the contract parameter PublicKey, which can be obtained through the API API. You need to save the result here, and you need to use the derivation_path corresponding to root_xpub and pubkey when unlocking the contract later.

4) compile the contract and return the result program is the lockable contract. (direct compilation of a contract produces contract execution steps. If such a contract is deployed, the user can directly construct the corresponding parameters and unlock it.)

3. Build a locked contract transaction.

The following shows locking 1000 assets of type 777e3586d2ec47c4974d262e0ff86fd3c1c063d242d32bdef71d6d16eed6763e into the contract 204e925f0fcc2f2618d96b7a3dce2aad28e60ab3339377760d48aea8ae8169ae417403ae7cac00c0. For more information, please see wiki: https://github.com/Bytom/bytom/wiki/API-Reference#build-transaction for building the transaction.

4. Signature transaction

For more information, please see the wiki: https://github.com/Bytom/bytom/wiki/API-Reference#sign-transaction of the signature transaction.

5. Submit the transaction

For more information, please see the wiki: https://github.com/Bytom/bytom/wiki/API-Reference#submit-transaction that submitted the transaction.

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

Third, unlock the contract process

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

The ID field indicates outputID.

2. Find the UTXO of the contract through list-unspent-outputs interface API according to outputID, and check whether the type and quantity of assets locked in the contract match.

3. Build the unlocked contract transaction, and the parameter for unlocking clause unlockWithSig is Signature, but the signature result can only be obtained after the sign-transaction is successful, so we only need to build the signature parameter. If the publicKey built previously is 4e925f0fcc2f2618d96b7a3dce2aad28e60ab3339377760d48aea8ae8169ae41, then the signature parameters are root_xpub and derivation_path, and the corresponding values are "dc903a862a14966d47dc6bc935c687c6cccb7a8f9c70f13bb82a41a0fe2696596cb141ff1840f90c75f8f25099f0dc50e005e1e36817d184b2b1eb1354b61575" and ["01040000000000000000", "010000000000000000"]. Its structure is as follows: (specific fields can be described in the official intelligence contract document)

4. Signature transaction. For more information, please see the wiki: https://github.com/Bytom/bytom/wiki/API-Reference#sign-transaction of the signature transaction.

5. Submit the transaction. For more information, please see wiki: https://github.com/Bytom/bytom/wiki/API-Reference#submit-transaction that submitted the transaction.

After the unlocking contract transaction is successfully packaged, the original contract UTXO is searched through the list-unspent-outputs API API according to outputID, which will be empty, otherwise the unlocking of the contract transaction fails.

At this point, I believe you have a deeper understanding of "how to compile publickey contracts". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report