Add transaction api logic and refactor