8.2.5 Interchain Services based on Neo Testnet

Application Contract Development Guide

The development of Neo application contract is based on its own business scenario. The main implementation includes two parts: if the source chain initiates a cross-chain transaction, its application contract needs to get outbound to access the target chain; if the target chain receives a cross-chain transaction, its application contract needs to get inbound. Neo's chain ID in the BSN Testnet is 4. This chain ID is registered in Poly Enterprise the configuration is applicable to both BSN Production Environment and Testnet.

Below is an example of a source chain initiating a cross-chain transaction call:

/// <summary>
        /// This method is used to make cross-chain calls to other target chains (this method is self-defining)
        /// </summary>
        /// <param name="toChainId">The chain ID of the target chain in the Poly network</param>
        /// <param name="msg">The cross-chain information that the target chain needs to pass to apply the contract</param>
        /// <returns></returns>
        [DisplayName("say")]
        public static bool Say(BigInteger toChainId, string method ,byte[] msg)
        {
            // Get the application contract on the target chain
            var toProxyHash = HelloPoly.GetProxyHash(toChainId);
            // Get the CCMC contract address
            var ccmcScriptHash = HelloPoly.GetProxyHash(neoChainID);
            // Call across the chains

           bool success = (bool)((DynCall)ccmcScriptHash.ToDelegate())("CrossChain", new object[] { toChainId, toProxyHash, method, msg });

            HelloPoly.Notify(success, "[HelloPoly]-Say: Failed to call CCMC.");
            // Event notification
            HelloPoly.SayEvent(toChainId, toProxyHash);
            return true;
        }

Below is an example of a target chain call when receiving a cross-chain transaction:

/// <summary>
        /// This method is used to make cross-chain calls to other target chains (this method is self-defining)
        /// </summary>
        /// <param name="fromChainId">The chain ID of the source chain in a Poly network</param>
        /// <param name="toChainId">The chain ID of the target chain in the Poly network</param>
        /// <param name="msg">Receive a cross-chain message sent by the source chain</param>
        /// <param name="callingScriptHash">Callback script hash</param>
        /// <returns></returns>
        [DisplayName("hear")]
        public static bool Hear(byte[] inputBytes, byte[] fromProxyContract, BigInteger fromChainId, byte[] callingScriptHash)
            //commit into ledger
            Storage.Put(fromProxyContract, inputBytes);
            // Event notification
            HearEvent(fromChainId, fromProxyContract, inputBytes);
            return true;
        }

Demo Contract Example

GitHub: https://github.com/BSNDA/ICH/tree/main/sample/polychain/neo-contract

© 2019-2023 Red Date (Hong Kong) Technology Limited. all right reserved,powered by GitbookFile Modify: 2023-02-16 12:21:44

results matching ""

    No results matching ""

    results matching ""

      No results matching ""