Skip to main content

Interaction Implementation

Each interaction starts with the user intent:

  • User wants to swap X A tokens for Y B tokens and stake B tokens
  • User wants to add liquidity to a pool
  • User wants to migrate liquidity from one pool to another
  • User wants to borrow assets
  • User wants to mint an NFT
  • User wants to buy the floor of a NFT collection

To implement a smart contract interaction on the client-side, developers need: a smart contract address, a method, an ABI and few SDKs.

Except the simplest transactions, the implementation gets more complicated:

  • Any DeFi transaction, even a swap, requires client-side computations
  • Buying a floor NFT from a marketplace requires off-chain data

For methods with parameters, frontend developers need to:

  • Read data from contracts
  • Get user state and react to user inputs
  • Format and compute amounts, deadline
  • Listen to events like chain changes and wallet changes
  • Customize interactions with the wallet balance of a given token
  • Compute slippage
  • Provide gas estimation
  • Compute and convert currencies
  • Include approvals: Even when developers want users to perform a single transaction, they might need two.
  • In some cases, they need to call other contracts to get data and inputs. To migrate DeFi pools, six transactions might be necessary.

The semantics of transaction requires assembling the parameters and getting the right inputs in that transaction.

Challenges

Developers face multiple challenges due to the differences between the mutable world of JavaScript and the decentralized immutable world of blockchains:

  • The semantics of interacting with blockchains are not specified
  • The actual client-side computations are lost or fragmented in the JavaScript codebase.
  • There is no standard way to get the data required to compute the transaction parameters, developers have to manually implement onchain and off-chain data.
  • Each transactional interface requires additional implementation, making the codebase hard to maintain and protect from vulnerabilities.

Our Approach

At OKcontract, we focus on standardization and automation. Our approach to properly implement and handle blockchain interactions on the client-side, boils down to the following:

  • A standard way to specify the smart contract interaction
  • Automated generation of the transactional interface from that specification
  • Streamlined integration of that automated interface into any web page/app
  • Transaction parameters computation from high-level inputs
  • An automated access to all required onchain and off-chain data
  • A client-side universal runtime for all interactions.

This approach is the foundation of the OKcontract Interaction Layer.