Retrieving LP token address from transaction address

I have been tinkering with the Deep API Index to try to find a way to grab the LP token address from a transaction address.

I have only found that I can search data by address or block, but can’t query information from transaction hash. Is it possible to do this or is there a workaround?

For example, how is is bscscan getting the LP address to show here on this page?

I have a Sync and Watch plugin running and there is no data that indicates the LP token address in the table so I am trying to figure out where I can find this missing information.

Thank you!

We could possibly add an endpoint to query by transaction hash. This something than can be done already though using web3.js by querying the blockchain directly (it’s a very specific lookup)

https://web3js.readthedocs.io/en/v1.3.4/web3-eth.html#gettransaction

A web3.js instance can be obtained in a cloud function this way:
https://docs.moralis.io/web3

It may require effort to extract the info you want from the transaction though. The transaction is a function call to the withdraw method where one of the params is address _lptoken which matches the address displayed by BscScan. If you look at the “Logs” tab you’ll see there’s an onWithraw event with the first param as lpToken which also matches the token address displayed on Bscscan.

It may be easier to subscribe to another event like onWithdraw to get this data.

BSc is doing a lot of stuff behind the scenes to know what’s going on.

1 Like

Thank you mayjer, this all really helps quite a bit.

web3js should do the job.

To give a bit more background I have a zapier set up that interacts with the BscScan API and pulls that input and parses the correct piece of the LP address and reconstructs the full LP address. Right now I am simply trying to mimick it on Moralis, but wasn’t sure if there was an easier way to get that info.

I imagine etherscan works the same way. I’m not sure how to go about subscribing to onWithdraw. I would use the plugin Sync and Watch Contract Events right? Wow. That really unlocked some additional understanding.

Thank you

1 Like

As a follow up, I’m not sure what to put for ABI for Sync and Watch Contract Events

The actual event I want to subscribe to is onDeposit

which in the contract looks like

event onDeposit(address lpToken, address user, uint256 amount, uint256 lockDate, uint256 unlockDate);

My understanding is I need to structure a JSON array so it knows how to add the data to the Moralis table? Not sure of the syntax here.

  • For the event topic use the event definition but remove all the parameter names and spaces, leaving only the data types: EventName(address,uint256)
  • For the ABI look up the contract on Etherscan and get the ABI from the contract tab, then search for the event name and only include the section related to the event

Relevant section of the docs:
https://docs.moralis.io/transactions-and-balances/realtime-transactions#defining

I set it up with blank ABI and got the default ABI so that worked.

With custom ABI, I’ve followed the bet example and traded out whatever makes sense to match the format. So I’ve gotten this so far:

For Topic:
onDeposit(address,address,uint256,uint256,uint256)

For Abi:

{
  "anonymous": false,
  "inputs": [
    {
      "indexed": true,
      "internalType": "address",
      "name": "lpToken",
      "type": "address"
    },
    {
      "indexed": true,
      "internalType": "address",
      "name": "user",
      "type": "address"
    },
    {
      "indexed": true,
      "internalType": "uint256",
      "name": "amount",
      "type": "uint256"
    },
    {
      "indexed": true,
      "internalType": "uint256",
      "name": "lockDate",
      "type": "uint256"
    },
    {
      "indexed": true,
      "internalType": "uint256",
      "name": "unlockDate",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "uint8",
      "name": "side",
      "type": "uint8"
    }
  ],
  "name": "onDeposit",
  "type": "event"
}

However the new table is empty. Trying some variations but not sure how to identify where the error is occuring.

That seems correct to me. Take a look at the Logs section in the dashboard, perhaps there is an error message that might be helpful. Might also try deleting the plugin, saving, then creating it again.

Tried from scratch and then also tried a different event. Both still nothing populates in the table.

Nothing in errors but on the log:

  1. 2021-07-09T22:31:08.591Z - {“sync_historical”:true,“chainId”:“0x38”,“description”:“onDepositAgain”,“topic”:“onDeposit(address,address,uint256,uint256,uint256)”,“abi”:{“anonymous”:false,“inputs”:[{“indexed”:true,“internalType”:“address”,“name”:“lpToken”,“type”:“address”},{“indexed”:true,“internalType”:“address”,“name”:“user”,“type”:“address”},{“indexed”:true,“internalType”:“uint256”,“name”:“amount”,“type”:“uint256”},{“indexed”:true,“internalType”:“uint256”,“name”:“lockDate”,“type”:“uint256”},{“indexed”:true,“internalType”:“uint256”,“name”:“unlockDate”,“type”:“uint256”},{“indexed”:false,“internalType”:“uint8”,“name”:“side”,“type”:“uint8”}],“name”:“onDeposit”,“type”:“event”},“address”:“0xC765bddB93b0D1c1A88282BA0fa6B2d00E3e0c83”,“tableName”:“onDepositAgain”}

Found the issue… for whatever reason the ABI that was originally copied is incorrect. You’ll notice the event definition has 5 values but the ABI posted above has 6 objects in the array :man_shrugging: here is the correct ABI. I’ve tested this and it works.

  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "address",
        "name": "lpToken",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "address",
        "name": "user",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "lockDate",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "unlockDate",
        "type": "uint256"
      }
    ],
    "name": "onDeposit",
    "type": "event"
  }
1 Like