Blockchain Events

Track purchase status with Blockchain Events.


Smart contract events allow you to track what is happening with escrows created by Ramp Instant widget using only the Ethereum blockchain. They don't give much visibility into how the process is going (did the user made payment or not, is the bank API working, or are there any errors), but they give you a definite confirmation when the escrow is successfully released (tokens are sent to the buyer) or if the tokens were returned to liquidity pool.

For watching the events you need our Escrows smart contract's ABI (only a fragment of it is necessary), its address, name of the event you want to watch and the swapHash identifier.

Smart contract

Address: 0x762a7ea687D5F9aAeD98Eb4c5e597b43652Af7Ff

ABI:

var ABI = {
  abi: [
    //...
    {
      anonymous: false,
      inputs: [
        {
          indexed: true,
          name: "swapHash",
          type: "bytes32"
        }
      ],
      name: "Released",
      type: "event"
    }
    //...
  ]
};

If you only want to watch one event (Released) this fragment is enough. Below you will find an example using this ABI.

Full reference: Escrows contracts

swapHash - Escrow identification hash

To watch only events related to a given escrow you need to know its escrow hash, which is like an ID for each escrow. There are couple of ways get this hash:

Events summary

  • Escrow is created
  • Escrow is released (tokens go to the buyer)
  • Escrow is returned (tokens go back to the liquidity pool)

Example

This code will run console.log when tokens from escrow with hash 0xc003...d516 will be successfully sent to the buyer.

var ABI = {
  abi: [
    //...
    {
      anonymous: false,
      inputs: [
        {
          indexed: true,
          name: "swapHash",
          type: "bytes32"
        }
      ],
      name: "Released",
      type: "event"
    }
    //...
  ],
  bytecode: ""
};

var MothershipETH = new web3.eth.Contract(
  ABI,
  "0x762a7ea687D5F9aAeD98Eb4c5e597b43652Af7Ff"
);

MothershipETH.once(
  "Released",
  {
    filter: {
      swapHash:
        "0xc003c2b6b7f2498e08565529cb9256ec6490ad914dbc3350e4917ac85dc5d516"
    },
    fromBlock: 0
  },
  function(error, event) {
    if (error) {
      console.error(error);
    } else {
      console.log(event);
    }
  }
);

The swapHash is from this transaction.