1. Introduction
Smart contracts are computer programs that automatically execute contracts based on blockchain technology. They are designed to enforce and verify the fulfillment of contractual terms in a decentralized, transparent, secure, and reliable manner. The concept of smart contracts was first proposed by Szabo [
1] in 1995 and has been widely used and developed in blockchain platforms such as Ethereum. With the rapid development of the blockchain and the widespread popularity of the Internet, the research and application of smart contract technology has also attracted the attention of many scholars [
2]. As a new form of contract, smart contracts write a contract’s terms into a computer programming language and start the automatic execution of the contract through the realization of preset conditions. When the conditions are met, the contract takes effect. It has the characteristics of decentralization and trustworthiness. It is also of a high quality, is not easy to be tampered with, and so on. Therefore, the use of blockchain smart contract technology can effectively solve the current problems of relying on third parties in various transactions, and contracts being easily interfered with by external factors such as civil disputes, to ensure the authenticity and reliability of information, as well as to prevent transaction fraud and false transactions. Transactions realize the definition of rights and responsibilities, and safeguard the legal and legitimate rights of both parties to the transaction.
At present, there are many application platforms for smart contracts. Ethereum is an open-source and general-purpose public blockchain platform with smart contract functions. Through its dedicated cryptocurrency, Ether, the Ethereum virtual machine is used to process point-to-point contracts [
3]. Hyperledger Fabric is a modular, open-source, enterprise-level, and permissioned distributed ledger technology platform that is designed to be used in an enterprise environment, providing functions such as pluggable implementations that support different components and channel creation [
4]. The enterprise operation system (EOS) is a blockchain underlying public-chain operating system designed for commercially distributed applications, with performance extensions for traditional applications [
5].
Cai [
6] provided a method and device for processing rule changes in smart contracts. The method provided can integrate a business rule engine in a smart contract, so that business personnel can formulate business rules conveniently and simply. Wang [
7] analyzed and compared existing smart contracts, gave a formal definition of contract-oriented smart contracts, and proposed a general smart contract implementation method independent of the blockchain platform. Hu [
8] pointed out that a formal verification framework applied to the life cycle of smart contracts should be proposed. The Prome modeling language was used to model smart shopping contracts, and SPIM was used to model monitoring to verify the effect of formalization on smart contracts. Mavridou [
9] designed smart contracts based on finite state machines, and provided a tool to create FSM on an easy-to-use graphical interface and automatically generate Ethereum contracts. Developers can easily add this to their contracts for enhanced security and functionality. Bai [
10] provided a general and formal description of the smart contract template. The model-checking tool SPIN was used to verify the correctness and necessary properties of the smart contract template, and verify the nature of smart contracts. Xu [
11] proposed a digital bond transaction contract system based on blockchain technology and studied the system’s architecture using blockchain technology to optimize the structure of the bond trading system, as well as using blockchain technology to develop the software’s architecture. Through a performance test of the system, the advantages of the system’s architecture in practical applications were verified. Han [
12] proposed a general framework for a blockchain platform to enable peer-to-peer (P2P) energy transactions in retail electricity markets. It focuses on finding energy-matching pairs from the supply and demand side, encourages direct energy transactions between producers and consumers, and realizes a complete energy transaction process. Shi [
13] proposed a transaction model based on legal contracts using smart contract templates. This model can dynamically construct, store, and call smart contracts based on smart contract templates and transactional contract contexts, thereby improving the reusability of smart contracts and reducing their difficulty of use. Nazari [
14] proposed a safe and automated blockchain-based framework, using the Solidity programming language and the MetaMask wallet to create smart contracts, allowing energy producers and consumers to conduct energy trades without intermediary entity interaction, and enhancing security and privacy.
To sum up, smart contracts have been widely used in transactions, but all smart contracts are designed based on the application field, and the structure and function of each smart contract is different, so the structure is chaotic, the development is repeated, and the level of sharing is low; there is not yet a standardized definition of the structure of smart contracts. Therefore, this article aims to tackle the current problems of smart contracts for transactions and establishes the general architectural specification of smart contracts, aiming to provide a general blueprint for reference and use when writing smart contracts for transactions. This architecture covers the key aspects and necessary components in the process of writing smart contracts, from transaction rule setting to breach of contract liability, from power and responsibility analysis to the reward and punishment mechanism, as well as data traceability, etc., to comprehensively define the design points of smart contracts for transactions. At the same time, the layered structure of the contract enables the targeted expansion of certain layers without affecting the performance of other layers, and the scalability of the contract can be realized.
2. Contract Structure Design
To fully understand the situation of smart contracts in the trading field, one can conduct in-depth research and data collection on the architecture of smart contracts. First, consult academic papers, research reports, and other literature sources to obtain design cases and related materials on smart contracts. The literature covers an in-depth analysis of smart contract design patterns, as well as contract structures and functional characteristics. In addition to extensively reviewing comprehensive information on smart contracts, it focuses on in-depth research on smart contract applications in specific industries. For example, focus on specific scenarios such as intellectual property transaction contracts and logistics tracking contracts in the supply chain field to obtain industry-specific design patterns and experiences. Focused research can provide specific examples of the application of smart contracts in specific fields, and can provide a more comprehensive understanding of the application and effect of smart contracts in actual business. Through case analysis and cross-industry comparison, it is possible to gain a comprehensive understanding of the design and application of the architecture of smart contracts, providing valuable references and guidance for future smart contract development. The research results are shown in
Table 1.
After conducting research on the architecture of smart contracts for transactions in various fields, analyze and compare these architectures to extract the common content of their main bodies, summarize, design a hierarchical structure on the whole, and build an overall specification for the architecture of smart contracts. The smart contract structure is divided into four parts: transaction rules, power and responsibility analysis, reward and punishment mechanism, and data traceability. The architecture of smart contracts is shown in
Figure 1.
Transaction rules refer to the rules and conditions defined in a transaction’s smart contract, which are used to guide and constrain the execution of transactions. By clearly defining transaction rules, smart contracts can ensure that only transactions that meet the specified conditions can be executed, avoiding illegal or incorrect transactions.
The rights and responsibilities analysis refers to clarifying the rights and responsibilities of each participant in a transaction’s smart contract. This includes the rights that the creators, participants, and possible external users of a contract have in the transaction, as well as the responsibilities and obligations they need to assume in the transaction. The rights and responsibilities analysis not only involves defining the rights and obligations of both parties in a transaction, but also needs to determine the rights and responsibilities in the case of transaction failure or breaches of contract to determine which party will accept the corresponding punishment. Through the analysis of rights and responsibilities, smart contracts can ensure that the roles and rights of participants in transactions are clear, thereby reducing transaction risks and ensuring the credibility and reliability of transactions.
The reward and punishment mechanism is a mechanism to motivate contract participants to abide by a contract’s rules, perform their duties, and contribute to the stability and security of the network. The reward mechanism encourages participants to actively participate in contract execution, while the penalty mechanism punishes participants who violate the contract to ensure contract execution and participants’ compliance with the rules.
Data traceability is the storage and traceability of data in a contract. Smart contracts usually need to store a transaction’s data and status changes for future audits and traceability. Data traceability ensures the security, reliability, and accessibility of contract data.
These four parts are the parts that need to be considered when designing smart contracts. These four parts are interrelated and together form a complete smart contract architecture to ensure the correct execution, security, and scalability of the smart contracts of transactions. Such a hierarchical design divides the intelligence into four parts, so that each part can be considered and designed independently, and the parts are interrelated to form a complete architecture of smart contracts. When designing a smart contract, it is necessary to comprehensively consider the characteristics of the transaction and fully consider the design and implementation of each part to meet the needs and goals of the transaction. At the same time, it is also necessary to follow the characteristics and limitations of the blockchain platform to ensure the efficient execution and stable operation of smart contracts. The smart contract flow chart is shown in
Figure 2.
2.1. Trading Rules
Transaction rules are the basis and guarantee of smart contracts, which define the operating logic and execution conditions of a contract. Reasonably designed transaction rules can ensure the safety, reliability, compliance, and fair execution of contracts, to achieve the expected goals and effects of smart contracts.
2.1.1. Transaction Parameter Verification
Transaction rules should define the validation requirements of transaction parameters. This includes verifying that the parameters provided by a transaction’s participants conform to the expected format, type, and value range. Through a comprehensive verification of a transaction’s parameters, smart contracts can prevent potential security breaches and malicious behaviors, ensuring the safety, reliability, and compliance of transactions. The verification of these parameters is a very important part of smart contracts to ensure the correctness of a transaction’s execution and the trust of its participants.
Time parameters: including transaction timestamp, transaction validity period, time interval, etc., usually string-type;
Numerical parameters: including the amount, quantity, price, and other numerical information involved in the transaction, usually int64- or float64-type;
Address parameters: including contract address, user wallet address, partner address, etc., usually string-type;
Boolean parameter: a logical value representing true or false, used to trigger a specific condition or flag, usually bool-type;
String parameters: including transaction description, text information, name, etc., usually string-type.
2.1.2. Trading Condition Setting
Transaction conditions mean that when certain preset conditions are met, the contract will execute a specific logic.
Time limit: it is stipulated that the transaction is only valid within a specific time range;
Authorization verification: to check whether a transaction initiator has the authority to execute a contract; for example, it must pass a specific signature verification;
Status Judgment: to judge whether the execution conditions are met according to the contract status before a transaction; the next transaction process can only be executed in a specific state.
2.1.3. Transaction Execution Logic
A transaction’s execution logic is the core of its smart contract, which defines the specific execution process and processing logic of the transaction. According to a transaction’s rules and conditions, the transaction execution logic determines how a contract should process a transaction, including updating its status, and performing operations and possible outcomes.
Contract operation: according to the transaction type and parameters, this executes the corresponding contract operation, such as to transfer or store data, trigger other contracts, etc.;
Data update: updates the relevant data and status involved in a transaction to ensure the correct execution and results of the transaction;
Exception handling: handles abnormal situations that may occur during transaction execution, such as insufficient account balance, transaction failure, etc.
2.1.4. Transaction Status Transition
A transaction’s status transition element is responsible for managing transaction status changes and state transitions. Smart contracts go through different states during execution, which may trigger other transaction conditions or cause changes in the status of a contract.
Status management: tracks the status changes during a transaction’s execution process to ensure that contracts are converted using the specified conditions in different states;
State transition conditions: define the transition conditions between different states to ensure that a contract can correctly perform state transitions when certain conditions are met;
State change event: when the state of a contract changes, corresponding events or operations are triggered, such as triggering other contracts, notifying transaction participants, etc.
2.2. Rights and Responsibilities Analysis
The rights and responsibilities analysis is the basis of smart contracts, which clarifies the rights and obligations of contract participants, constrains their behavior, and ensures the safety, reliability, compliance, and fair execution of contracts. A reasonably designed rights and responsibilities analysis will help toward achieving the expected goals and effects of smart contracts, and improve the satisfaction and trust of contract participants.
2.2.1. Rights of Participants
It is necessary to clarify the rights that each participant has in a transaction. This may include initiating transactions, viewing transaction information, accessing the status of contracts, etc., to ensure that participants enjoy the rights they deserve in a transaction to meet their transaction needs.
2.2.2. Responsibilities of the Participants
It is important to determine the responsibilities and obligations of each party involved in a transaction. This may involve conditions and restrictions of transactions, as well as a duty to abide by the rules of a contract. Participants need to clearly understand their responsibilities in a transaction to ensure the normal execution of its contract and the smooth progress of the transaction.
2.2.3. Determination of Responsibilities
When a transaction fails or a breach of contract occurs, a rights and responsibilities analysis can evaluate and judge the behavior of a contract’s participants to determine the responsible party and implement the corresponding punishment measures according to the contract. The identification of rights and responsibilities ensures that, in the event of transaction disputes or misconduct, responsibilities can be clarified and the legality, fairness, and stability of transactions can be maintained.
2.3. Reward and Punishment Mechanism
The reward and punishment mechanism is an incentive measure designed to encourage a contract’s participants to abide by the contract’s rules and actively perform the contract’s tasks. A properly designed reward and punishment mechanism can increase the enthusiasm and willingness of participants to co-operate, thereby improving the execution efficiency of smart contracts, the stability of the network, and the overall development effect.
2.3.1. Credit Score System
Smart contracts can adopt a reputation scoring system to set up a reputation scoring mechanism for participants. When participants complete transactions or abide by contract rules, they can obtain certain reputation points. Depending on the level of reputation points, some rights and privileges of participants in a contract can be affected. Participants with high reputation scores may receive more rewards and greater authority, while participants with low reputation scores may face certain restrictions or penalties.
2.3.2. Fine
Smart contracts can set up a penalty mechanism, and when participants violate contract rules or fail to perform their obligations, the contract can fine them. The cost of the penalty can be set according to the degree of the breach of contract and the degree of loss, and is used to make up for the loss of the injured party.
2.3.3. Penalty Period
A contract can stipulate the processing period for breaches of contract; that is, the breaching party needs to remedy or solve the problem within a certain period. If a breach is not resolved within the stipulated period, the contract can proceed with other penalties.
2.3.4. Arbitration
The application for arbitration is usually a dispute resolution mechanism that is used when a dispute or breach of contract occurs during the execution of a contract. When the parties involved in a contract cannot solve the problem by themselves or reach an agreement, they can apply to the arbitration institution. The arbitrator reviews the terms of the contract, its performance, and the relevant evidence before making an award. The outcome of this arbitration process is enforced via smart contracts to resolve disputes.
2.4. Data Traceability
By tracing a transaction’s history, the detailed information of the transaction, the identity and behavior of the participating parties, and related time stamps can be viewed. This evidence can be used to resolve disputes, adjudicate disputes, and support the arbitration process. At the same time, it provides a comprehensive visibility and transparency of a transaction’s history. Anyone can trace and verify the source, participants, time, and related information of a specific transaction, which enhances the credibility of the transaction and reduces the possibility of fraud and improper behavior, including sexual misconduct.
Smart contracts record the details of transactions and store them in the blockchain. This information includes transaction time, the identity information of a transaction’s participants, relevant data on items, etc. Such records ensure the traceability of transactions, enabling parties to query and verify the authenticity and integrity of transactions. When querying a certain transaction, one can query through the unique hash value of a transaction, traverse the entire blockchain, and return the transaction record with the same hash value. Each block contains the hash value of the previous block, forming an immutable chain structure. If someone tries to tamper with the previous transaction records, the integrity of the entire blockchain will be destroyed, ensuring that the transaction’s information cannot be tampered with. The transaction traceability process is shown in
Figure 3.
4. Summary and Outlook
This paper formulates a smart contract framework for the blockchain transaction field. The contract includes four parts: transaction rules, power and responsibility analysis, a reward and punishment mechanism, and data traceability. This architecture can be applied to transaction-related smart contracts, and allows for corresponding customization and improvement according to the specific application environment. Designing this general architecture can solve the problem of the duplication of labor in the development of current trading smart contracts. The simulation experiment also proves the feasibility of the architecture, which assists in the development of blockchain smart contracts in the transaction field.
In future work, this architecture will be optimized to make it more efficient, secure, and scalable, while considering how to reduce a transaction’s execution time, reduce transaction costs, and improve the system throughput. For the future, we propose standardized specifications for smart contracts to promote interoperability and portability between different platforms and applications, as well as the combining of this architecture with actual application scenarios to achieve more complex functions, such as supply chain management, the Internet of Things, digital asset transactions, and other fields, so that smart contracts can be more widely used.