diff --git a/kip-0032.md b/kip-0032.md new file mode 100644 index 0000000..7d3de55 --- /dev/null +++ b/kip-0032.md @@ -0,0 +1,74 @@ +--- +KIP: "0032" +Title: Cross-Chain Function Call Syntax Enhancement by Including Chain ID in Function Calls +Author: @DaisukeFlowers +Status: Draft +Type: Improvement +Category: Pact +Created: 2024-11-04 +--- + +# KIP-0032: Cross-Chain Function Call Syntax Enhancement by Including Chain ID in Function Calls + +## Abstract + +Introducing a syntax that includes the chain ID in the function call to enable direct cross-chain interactions. This proposal aims to simplify cross-chain workflows by allowing function calls across chains, which is currently limited to data transfer only. With this change, cross-chain communication becomes more intuitive and flexible, making the development of complex interactions more efficient. + +## Motivation + +Kadena's current cross-chain communication utilizes `defpact`, `yield`, and `resume` constructs to transfer data between chains. While effective for data exchange, this approach is limited and can become complex for developers who need to execute functions or retrieve information from other chains directly. + +### Why This Change? +1. **Expanding Cross-Chain Interactions**: Allowing direct function calls across chains enables richer, more flexible cross-chain workflows, enhancing Kadena’s interoperability capabilities. +2. **Streamlining Development**: The proposed syntax reduces the need for complex `yield` and `resume` sequences, making code more readable and easier to maintain. +3. **Enhanced Usability**: Developers gain a simpler and more intuitive way to manage cross-chain communication, which enhances productivity and reduces the risk of errors in complex multi-chain workflows. + +## Detailed Specification + +### New Syntax: `chain.namespace.contract.function` +- **Parameters**: + - `chain`: The ID of the target chain. + - `namespace`: The namespace of the contract. + - `contract`: The name of the contract. + - `function`: The function to be called. + +### Function Call +- **Current form**: `(namespace.contract.function PARAMETERS)` +- **Proposed form**: `(chain.namespace.contract.function PARAMETERS)` + + If no chain ID is specified, the function defaults to the chain of the executing contract. + +## Example Usage + +### Current Cross-Chain Data Transfer (with `defpact`) +```pact +(defpact crossChainTransfer + (step "Step 1" (yield { "data-key": data-value })) + (step "Step 2" (resume { "data-key":= data-value }))) +``` + +### Proposed Cross-Chain Function Call +```pact +(chain123.namespaceX.contractY.functionZ PARAMETERS) +``` + +This allows developers to call `functionZ` directly on `chain123` within `namespaceX.contractY`. + +### Example +```pact +;; Current usage +(free.token.get-balance ACCOUNT) + +;; Proposed usage +(1.free.token.get-balance ACCOUNT) +``` + +## Backward Compatibility + +The proposal is fully backward-compatible. The existing `(namespace.contract.function PARAMETERS)` syntax remains unchanged for single-chain calls. + +## Benefits + +- **Enhanced Interoperability**: Directly execute functions on other chains, expanding cross-chain capabilities. +- **Developer Productivity**: Simplifies code and reduces the learning curve for managing cross-chain operations. +- **Flexible Workflows**: Allows seamless multi-chain interactions without multi-step, complex setups.