Example : Chainlink Price Feed

A simple smart contract call to the Chainlink ETH/USD Pricefeed on Polygon Mumbai Testnet from your SAP system

Configuration instructions

Retrieve the required ABI file from https://mumbai.polygonscan.com/address/0x0715A7794a1dc8e42615F059dD6e406A6594651A#code

Select the Export ABI button to save the file as pricefeed.abi.json

Upload the pricefeed.abi.json file to a chosen location on your SAP system through transaction code CG3Z. If your system does not tcode CG3Z - try using using the zapcommander for an open source ABAP tool for uploading files to AL11 directories

Use transaction code SM30 on the ZPRVDABIREGISTRYtable to create an entry

Create a table entry with the following parameters (the entries are case sensitive!)

PRVD Nchain Network ID 4251b6fd-c98d-4017-87a3-d691a77a52a7

Smart contract address 0x0715A7794a1dc8e42615F059dD6e406A6594651A

File location: Use the AL11 file location you uploaded the file to

We are looking to improve the UX of this process with a SAPUI5 Fiori App. Contact us if you are interested in how you can contribute!

Running an example

Heads up! While this example doesn't require a zero knowledge proof here - you do still need and entry in the ZPRVDTENANTS table to authenticate to Polygon via PRVD Nchain.

If you successfully set up a subject account in Shuttle earlier - that should suffice. Otherwise you can set up an organization and vault using the PRVD CLI and maintain the org in SAP using the Postman collection

For a basic example : You can copy / paste the following ABAP code into a report and execute

PARAMETERS: p_tenant TYPE zprvdtenantid,
            p_sbjact TYPE zprvdtenantid,
            p_wrkgrp TYPE zprvdtenantid.
            
DATA: lo_prvd_api_helper TYPE REF TO zcl_prvd_api_helper,
      lo_prvd_nchain_helper TYPE REF TO zcl_prvd_nchain_helper,
      ls_execute_contract_resp TYPE zif_prvd_nchain=>ty_executecontract_resp.

lo_prvd_api_helper = NEW zcl_proubc_api_helper( iv_tenant = p_tenant iv_subject_acct_id = p_sbjact  iv_workgroup_id = p_wrkgrp ).
lo_prvd_api_helper->get_nchain_helper( IMPORTING eo_prvd_nchain_helper = lo_prvd_nchain_helper ).

"Debug into this call to look further into smart contract integration
lo_prvd_nchain_helper->call_chainlink_pricefeed(
      EXPORTING
        iv_inputcurrency  = 'ETH'
        iv_inputamount    = '1'
        iv_outputcurrency = 'USD'
      IMPORTING
        es_contract_resp = ls_execute_contract_resp
).

For a more advanced example: You can also check out our Chainlink Fall 2022 Hackathon Entry for a more advanced example that alters the foreign exchange rates maintained in SAP in the table TCURR.

Regardless of what way you choose to explore using smart contracts in ABAP, you should receive a JSON HTTP response at the end of the call_chainlink_pricefeed method like this

{
    "confidence": null,
    "ref": "e71f3955-77e7-4a39-8abd-ee129c9f28b1",
    "response": [
        18446744073709652396,
        155343681484,
        1666975920,
        1666975920,
        18446744073709652396
    ]
}

Interpreting the results

The output values in Nchain response can appear quite raw - but they do correspond precisely to the outputs defined in the smart contract function we called. Note how the solidity function below corresponds to the smart contract outputs received.

function latestRoundData() public view virtual override
returns (
 uint80 roundId,
 int256 answer,
 uint256 startedAt,
 uint256 updatedAt, uint80 answeredInRound
)

Source:

Feel free to poke around the block explorer for the smart contract a bit more - it's full of useful information!

Last updated