NexScript is a high-level smart-contract language and SDK for the Nexa blockchain, designed to make it easier for developers to write and deploy complex smart contracts. It provides a familiar syntax similar to JavaScript and Solidity, reducing the learning curve associated with Nexa’s native scripting language, Script. NexScript compiles high-level code into the raw Script that runs on Nexa’s virtual machine, offering strong abstraction and efficiency in building decentralized finance (DeFi) applications.
Lowering the Barriers to Building on Nexa: NexScript simplifies the development process by providing a higher-level language, making Nexa’s blockchain more accessible to developers and businesses.
Efficient Verification and Privacy: Nexa smart contracts are stateless and use the UTXO model, which allows for independent and efficient verification of transactions. Contracts are isolated from each other, reducing systemic risks and simplifying upgrades, while preserving privacy through P2ST.
DeFi Compatibility: With features like Script Templates, transaction introspection, covenants, and local state, NexScript makes it possible to build DeFi applications on Nexa, using its unique UTXO-based architecture.
NexScript Multiplex Contracts
NexScript introduced a significant upgrade with the release of Multiplex Contracts, which revolutionizes how smart contracts are structured and executed on the Nexa blockchain.
Multiplex Contracts are a collection of contracts that can define complex relationships between UTXOs (Unspent Transaction Outputs), enabling dynamic, persistent entities that overcome the traditional ‘single-use’ limitation of UTXO-based contracts.
What are Multiplex Contracts?
Multiplex Contract Paths (MCPs) combine MAST technology with advanced covenants, allowing for the creation of multi-UTXO smart-contract architectures within a single NexScript file. This design enhances scalability and brings NexScript’s capabilities closer to the level of Solidity and EVMs.
Multiplex contracts enable dynamic interactions between contracts through new ‘Accessor’ functions that can access properties of other contracts, such as:
Template bytecode
Template hash
Constraint hash
Visible parameters
Locking bytecode
Here’s an example of how multiple contracts within a single NexScript document can interact:
pragma nexscript ^0.7.0;
contract A() {
function A(string vA, int x) {
bytes lockingBytecode = B.lockingBytecode;
require(tx.lockingBytecode == lockingBytecode);
require(vA == "A");
require(x == 1);
}
function B(string vA, int x) {
require(vA == "B");
require(x == 2);
}
}
contract B() {
function Bv(string vB) {
require(vB == "B");
}
}
contract C() {
function Cv(string vC) {
bytes20 hash = A.templateHash;
require(hash.length != 0);
require(vC == "C");
}
}
In this example, contracts interact by locking outputs to other contracts’ code, allowing for a highly scalable and flexible architecture.
Unlocking the Future of UTXO Smart Contracts
Multiplex smart-contract architecture allows for virtually limitless programmability on the Nexa blockchain. With features such as:
DAOs in their most complex form
DeFi applications similar to those on Ethereum (ETH) or Solana (SOL)
Constant Product Market Makers (like Uniswap)
Stablecoins via entities like MakerDAO, including algorithmic stablecoins
Developers can create contracts that support complex optionality and the ability for contracts to constrain their offspring UTXOs with other contracts. Essentially, anything known in the DeFi world is possible on Nexa, but with native speed, scalability, and low fees.
NexScript 1.0: Major Advancements
NexScript reached a significant milestone with the release of NexScript 1.0, which introduced two major advancements:
Advanced Transaction Builder: The new SDK upgrade allows developers to create transactions that utilize multiple different smart-contract UTXOs as inputs. Previously, all inputs needed to share the same smart-contract code, but now, interactions are almost limitless. Smart contracts can communicate with each other thanks to new introspection functionality.
Find detailed documentation here.
Huge Smart-Contract Storage: NexScript now supports smart contracts that can manage their own off-chain databases, which are updatable and permissioned by the contracts themselves. Unlike MAST contracts that restrict execution to specific codes, this new storage capability is generalized, allowing any data to be stored and used.
Contracts can now create databases with up to 1,048,576 data entries and can chain multiple databases hierarchically for even more storage. These databases are not stored on-chain; only a commitment to the storage is on-chain, ensuring efficiency.
Find more details on this feature here.