NEOPIN Docs
  • NEOPIN Introduction
    • Vision
    • Permissioned DeFi Protocol
  • ✅GET STARTED
    • Download App
    • Create Wallet
    • Sign in (Import Wallet)
    • App settings
    • NEOPIN Wallet
  • 📈EARN WITH NEOPIN
    • Index
      • How it works
      • Backtest
      • RWA Project Index (RPI)
        • [RPI] Rebalancing History
          • [RPI] 28.08.2024 Rebalance
          • [RPI] 02.01.2025 Rebalance
          • [RPI] 27.03.2025 Rebalance
          • [RPI] 14.04.2025 Rebalance
      • Ethereum Family Index (EFI)
        • [EFI] Rebalancing History
          • [EFI] 09.09.2024 Rebalance
          • [EFI] 02.01.2025 Rebalance
          • [EFI] 27.03.2025 Rebalance
      • AI Titans Index (ATI)
        • [ATI] Rebalancing History
          • [ATI] 09.09.2024 Rebalance
          • [ATI] 02.01.2025 Rebalance
          • [ATI] 27.03.2025 Rebalance
      • [App] Index Guide
      • [Web] Index Guide
    • Derivatives
      • RWA
        • [App] NEOPIN BDLP Guide
        • [Web] NEOPIN BDLP Guide
      • Yield Aggregator
        • [App] NEOPIN SDLP Guide
        • [Web] NEOPIN SDLP Guide
    • Pool
      • [App] Pool Guide
      • [Web] Pool Guide
      • Impermanent Loss
    • Swap
      • [App] Swap Guide
      • [Web] Swap Guide
      • Automated Market Maker
    • Stake
      • [App] Stake Guide
      • [Web] Stake Guide
    • Liquid Stake
      • Why is my 1 npETH less than 1 ETH?
      • Unstake with npToken
      • [APP] Liquid Stake Guide
      • [WEB] Liquid Stake Guide
    • Bridge
      • [App] Bridge Guide
      • [Web] Bridge Guide
  • 🔷MEMBERSHIP
    • NEOPIN Club Membership: Current
      • How it works
      • Membership Points
      • Weighted Point Multiplier for Each Product
      • Participant Distribution Across Tiers
      • NEOPIN Club Membership Benefits
    • The First Season: 2023
      • Introduction
      • How It Works
      • How To Earn Points
        • Weighted Point Multiplier for Each Product
      • Leaderboard
      • Participant Distribution Across Tiers
      • Gift Box & Opening
      • Transition to NEOPIN Club Membership (S1 SBT)
  • 📣Referral
    • NEOPIN Referral Program
      • How it works
      • How To Earn Points
      • Leaderbord
  • 🗳️Governance Vote
    • Introduction
    • NEOPIN Governance Vote
    • Klaytn Governance Vote
    • [Deprecated] Finschia Governance Vote
    • [App] Governance Voting Guide
    • [Web] Governance Voting Guide
  • ↗️Kaia Migration
    • (EN) Klaytn x Finschia Merger to Kaia
      • Guide for FNSA holder
        • [Mobile] Guide to convert FNSA to KAIA
        • [Web] Guide to convert FNSA to KAIA
      • Guide for nFNSA holders
        • [App] Guide to convert nFNSA to KAIA
        • [Web] Guide to convert nFNSA to KAIA
      • Guide to Stake KAIA
  • 📊TOKENOMICS
    • NEOPIN Economy
      • NPT Tokenomics
      • Automated Reallocation Mechanism (AutoRM)
      • Issuance and Allocation
  • 🎉EVENT
    • [Closed] NEOPIN DeFi Carnival
  • 🗓️ROADMAP
    • #2023
    • #2024
  • 📃DLT Framework
    • NEOPIN Protocol DLT Framework
  • 💻DEVELOPERS
    • WalletConnect 2.0
      • Namespaces
      • Mobile Linking
      • Methods
        • EVM Methods
        • Cosmos Methods
    • Deprecated
      • (Deprecated) NEOPIN Connect 1.0
        • DApp
          • Android
            • Installation
            • Usage
            • Functions
            • SDK Components
            • Reference
            • Version History
          • iOS
            • Installation
            • Usage
            • Functions
            • SDK Components
            • Reference
            • Version History
          • Web
            • Installation
            • Usage
              • web3-react
              • Neopin Connect Modal
            • Reference
            • Related Package
            • Sample DApp Page
          • Unity
            • Installation
            • Usage
            • SDK Components
            • Reference
            • Version History
        • Wallets
          • Android
            • Installation
            • Usage
              • Connect
              • Approve
              • Transaction
          • iOS
            • Installation
        • JSON-RPC API Methods
        • Error Code
        • Technical Specification
  • 🔗LINKS
    • Website
    • NEOPIN Web
    • Android App Download
    • iOS App Download
    • Community Links
    • Contact us
Powered by GitBook
On this page
  • Connect
  • Close
  • GetAccount
  • SendTransaction
  • SignTransaction
  • PersonalSign
  1. DEVELOPERS
  2. Deprecated
  3. (Deprecated) NEOPIN Connect 1.0
  4. DApp
  5. iOS

Functions

Descriptions of NEOPIN Connect functions

The following information is deprecated and may limit its use. Please refer to the WalletConnect 2.0 tab for the latest version of NEOPIN wallet integration: WalletConnect 2.0

Type
Descriptions

Method for connecting with the NEOPIN Wallet, and the URL is returned when the connection is made.

ex) ConnectManager.shared.connect()

Method for disconnecting from the NEOPIN Wallet. Disconnect is recommended in the following cases.

  • When the app is terminated or forcibly terminated. (AppDelegate.applicationWillTerminate)

  • When the transaction with NEOPIN Wallet is finished.

  • When a certain time passes after connecting to NEOPIN Wallet.

ex) ConnectManager.shared.disconnect()

Method for obtaining the address of the NEOPIN Wallet.

Addresses can be imported only when Wallet is connected.

ex) ConnectManager.shared.getMyAccount()

Among the methods for communicating with the NEOPIN Wallet, this is the most important method. After sending a Transaction to the wallet, you must give a response value from the Wallet to receive it as a Response.

  • When creating a Transaction in this method, be sure to check the variable values (from, to, data, gas, gasPrice, value, nonce, type, accessList, chainId, maxPriorityFeePerGas, maxFeePerGas).

  • When creating a Client.Transaction object for SendTransaction, specify the ChainID of the target network. (*Required)

  • Data, one of the values of Transaction, must be entered as encodedData that complies with ERC-20 “Transfer”. Please refer to the example.

Signs a transaction that can be submitted to the network

The sign method calculates an Ethereum specific signature with:sign(keccack256("\x19Ethereum Signed Message:\n" + len(message) + message))).

Connect

Method for connecting with the NEOPIN Wallet, and the URL is returned when the connection is made.

The code block below is a code that requests connection to the NEOPIN Wallet through ConnectManager and opens the NEOPIN Wallet through the obtained URL.

You must request a connection and approve it in the NEOPIN Wallet to connect to the Wallet.

guard let connectionURL = ConnectManager.shared.connect() else {
        print("Connection Fail")
        return
}
        
let deepLinkURL = "examplewallet\(connectionURL)"
guard let url = URL(string: deepLinkURL) else { return }
UIApplication.shared.open(url, options: [:], completionHandler: nil)

Close

Method for disconnecting from the NEOPIN Wallet.

Disconnect is recommended in the following cases.

  • When the app is terminated (AppDelegate.applicationWillTerminate)

  • When the transaction with NEOPIN Wallet is finished

  • When connected to NEOPIN Wallet, but a certain amount of time has elapsed

func disconnect(){
    guard let session = self.session else { return }
    do {
        try self.client?.disconnect(from: session)
    } catch {
        print("Current Session is Nil: \(error)")
    }
}

ex) ConnectManager.shared.disconnect()

GetAccount

Method for obtaining the address of the NEOPIN Wallet.

Addresses can be imported only when Wallet is connected.

func getMyAccount(){
    guard let session = self.session,
      let from = session.walletInfo?.accounts.first else { return }
    
    print("getMyAccount: \(from)")
}

ex) ConnectManager.shared.getMyAccount()

SendTransaction

Method for communicating with the NEOPIN Wallet.

The following procedure is required to use NEOPIN Connect_sendTransaction in DApp.

  • Create Transaction encodedData compliant with ERC-20.

    • Data, one of the values of Transaction, must be entered as encodedData that complies with ERC-20 “Transfer”. Please refer to the example.

    struct ABIHelper {
        static func encode(
            param: [AnyObject]?,
            function: ABI.Element.Function?
        ) -> String? {
            guard let param = param else { return nil }
            guard let function = function else { return nil }
            let object = ABI.Element.function(function)
            guard let encodedData = object.encodeParameters(param) else { return nil }
            return "0x" + encodedData.toHexString()
        }

    • Create Transaction by filling in the remaining values.

      • When creating a Transaction in this method, be sure to check the variable values. In this project, an arbitrary value is set. (from, to, data, gas, gasPrice, value, nonce, type, accessList, chainId, maxPriorityFeePerGas, maxFeePerGas).

    static func transaction(
        from address: String,
        to: String
    ) -> Client.Transaction? {
        // MARK: - transferFucntion(address, value)
        guard let amount = Web3.Utils.parseToBigUInt("10000", units: .eth) else { return nil }
        guard let data = ABIHelper.encode(
            param: [
                to as AnyObject,
                amount as AnyObject
            ],
            function: ABIHelper.getTransferFunction()
        ) else { return nil }
        
        return PodsNeopinConnect.Client.Transaction(
            from: address,
            to: to,
            data: data,
            gas: "0x76c0",
            gasPrice: "0x",
            value: "0x",
            nonce: "0x",  //Update to the latest nonce from the NEOPIN Wallet.
            type: nil,
            accessList: nil,
            chainId: nil,
            maxPriorityFeePerGas: nil,
            maxFeePerGas: nil
        )
    }

    • Transfer to the NEOPIN Wallet.

      • Please create a Transaction object after checking Address(From, To).

      • After sending the Transaction to the Wallet, you can receive Response only when the wallet gives a response value.

    func requestSendTransaction(){
        guard let session = self.session,
              let from = session.walletInfo?.accounts.first else { return }
    
        guard let transaction = Stub.transaction(
            from: from,
            to: "0xb093add5a8ad3e997ccbde6d12dfb2e0c2befbb7"
        ) else { return }
            
        do {
            try self.client?.eth_sendTransaction(
                url: session.url,
                transaction: transaction,
                completion: { [weak self] response in
                    guard let self = self else { return }
                    do {
                        if let error = response.error {
                            let log = """
                            function: \(#function)
                            error: \(error)
                            """
                            self.appendLog(log: log)
                            return
                        }
                            
                        let result = try response.result(as: String.self)
                        print("requestSendTransaction: \(result)")
    
                        ABIHelper.decodedABIInfo(data: result)
                           let log = """
                           function: \(#function)
                           result: \(result)
                        """
                        self.appendLog(log: log)
                       } catch {
                        print("\(#function) error: \(error)")
                        let log = """
                           function: \(#function)
                           response.result error: \(response.error?.localizedDescription ?? "")
                           """
                           self.appendLog(log: log)
                       }
                   }
               )
       } catch {
            let log = """
            function: \(#function)
            eth_sendTransaction error: \(error)
            """
            self.appendLog(log: log)
        }
    }

SignTransaction

  • Transfer to the NEOPIN Wallet.

    • Please create a Transaction object after checking Address(From, To).

    • After sending the Transaction to the Wallet, you can receive Response only when the wallet gives a response value.

  • Signs a transaction that can be submitted to the network

// MARK: - requestSignTransaction
    func requestSignTransaction(chain: Chain) {
        guard let session = self.session,
              let from = session.walletInfo?.accounts.first else { return }
        
        guard let transaction = Stub.transaction(
            from: from,
            to: "0xb093add5a8ad3e997ccbde6d12dfb2e0c2befbb7",
            chain: chain
        ) else { return }
        
        do {
            try self.client?.eth_signTransaction(
                url: session.url,
                transaction: transaction,
                completion: { [weak self] response in
                    guard let self = self else { return }
                    do {
                        if let error = response.error {
                            let log = """
                            function: \(#function)
                            error: \(error)
                            """
                            self.appendLog(log: log)
                            return
                        }
                        
                        let result = try response.result(as: String.self)
                        print("requestSignTransaction: \(result)")

                        ABIHelper.decodedABIInfo(data: result)
                        let log = """
                        function: \(#function)
                        result: \(result)
                        """
                        self.appendLog(log: log)
                    } catch {
                        print("\(#function) error: \(error)")
                        let log = """
                        function: \(#function)
                        response.result error: \(response.error?.localizedDescription ?? "")
                        """
                        self.appendLog(log: log)
                    }
                }
            )
        } catch {
            let log = """
            function: \(#function)
            eth_signTransaction error: \(error)
            """
            self.appendLog(log: log)
        }
    }

PersonalSign

  • The sign method calculates an Ethereum specific signature with:sign(keccack256("\\x19Ethereum Signed Message:\\n" + len(message) + message))).

  • By adding a prefix to the message makes the calculated signature recognisable as an Ethereum specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.

  • Note See ecRecover to verify the signature.

func requestPersonalSign() {
        guard let session = self.session,
              let from = session.walletInfo?.accounts.first else { return }
        guard let url = ConnectManager.shared.session?.url else { return }
        
        do {
            try self.client?.personal_sign(
                url: url,
                message: "Test",
                account: from,
                completion: { [weak self] response in
                    guard let self = self else { return }
                    do {
                        if let error = response.error {
                            let log = """
                            function: \(#function)
                            error: \(error)
                            """
                            self.appendLog(log: log)
                            return
                        }
                        
                        let result = try response.result(as: String.self)
                        print("requestSendTransaction: \(result)")

                        ABIHelper.decodedABIInfo(data: result)
                        let log = """
                        function: \(#function)
                        result: \(result)
                        """
                        self.appendLog(log: log)
                    } catch {
                        print("\(#function) error: \(error)")
                        let log = """
                        function: \(#function)
                        response.result error: \(response.error?.localizedDescription ?? "")
                        """
                        self.appendLog(log: log)
                    }
                }
            )
        } catch {
            print("\(#function) error: \(error)")
            let log = """
            function: \(#function)
            response.result error: \(error.localizedDescription )
            """
            self.appendLog(log: log)
        }
    }
PreviousUsageNextSDK Components

Last updated 1 year ago

💻
Connect
Close
getAccount
sendTransaction
SignTransaction
PersonalSign