## 3 Methodology
### Blockchain-Based Framework for Factory Supply Chain Management  
To ensure secure and transparent traceability in factory supply chains, we propose a blockchain-based framework that leverages smart contracts for automatic execution of transactions. Blockchain technology provides a decentralized, immutable ledger that can securely record and verify transactions, actions, and identities, thus enabling trustworthy exchanges between multiple parties. The proposed framework, as illustrated in Figure 4, utilizes digital technologies, such as QR/bar codes, RFID, NFC, sensors, and mobile devices, to capture tracing data at various stages of the supply chain. These data are then recorded on the blockchain network, where each transaction is verified by the majority of participants to reach a global consensus, thus ensuring the information source is auditable and transparent. The decentralized nature of blockchain eliminates the need for a centralized third party and enables reliable product traceability. Figure 3: The framework of our proposed SAC-rainbow algorithm. Smart contracts play a crucial role in connecting business logic and supply chain activity process execution within the blockchain-based framework. These event-driven programs are stored in the blockchain database and executed autonomously on the selected blockchain platform. We developed two key smart contracts, identity management and resource management, using Solidity programming language for execution on the Ethereum platform. Identity Management Smart Contract:  
This contract is vital for managing the registration, authentication, and revocation of participants within the blockchain, thus ensuring that only authorized individuals can access and interact with the system. Here is a simplified fragment of the Solidity code used for these functions:  
pragma solidity '0.8.0;  
contract IdentityManagement {  
struct User {  
uint id;  
string name;  
address userAddress;  
bool isRegistered;  
mapping(address \(\Rightarrow\) User) public users;  
address[] public userAccounts;  
function registerUser(address _userAddress, string memory _name, uint _id) public ( require(!users[_userAddress],isRegistered, \"User already registered\". );  
users[_userAddress] = User(_id, _name,_userAddress, true);  
userAccounts.push(_userAddress);  
function authenticateUser(address _userAddress) public view returns (bool) {  
require(users[_userAddress],isRegistered, \"User not registered\". );  
return true;  
Figure 4: The framework of our proposed blockchain module. function revokeUser(address_userAddress) public {  require(users[_userAddress].isRegistered, \"User not registered\". );  users[_userAddress].isRegistered = false;  }  }  Resource Management Smart Contract:  This contract handles the validation and verification of transactions related to resource allocation and usage, thus ensuring all transactions are consistent with the agreed terms and recorded immutably on the blockchain. pragma solidity \"0.8.0;  
contract ResourceManagement {  struct Resource {  uint resourceId;  string resourceType;  uint quantity;  bool isAvailable;  }  
mapping(uint => Resource) public resources;  
function addResource(uint _resourceId, string memory _resourceType, uint _quantity) public {  resources[_resourceId] = Resource(_resourceId, _resourceType, _quantity, true);  }  
function updateResource(uint _resourceId, uint _quantity) public {  require(resources[_resourceId].isAvailable, \"Resource not available\". );  resources[_resourceId].quantity = _quantity;  }  }  
The identity management smart contract is responsible for managing the registration, authentication, and revocation of nodes, thus ensuring that only authorized participants can access and contribute to the system. It also manages access to system resources, thus ensuring that participants have the appropriate permissions to perform their roles within the supply chain. The resource management smart contract handles the validation and verification of transactions communicated over the network.