The 26-year-old was the Swans' top scorer with 12 last season after signing on a free transfer from Marseille in 2015.
Ayew is now discussing personal terms with the Hammers.
Swansea hope to complete the signing of Atletico Madrid striker Borja Baston to add to the arrival of Spain forward Fernando Llorente from Sevilla.
The Welsh club have also enquired about Leicester City's Argentine striker Leonardo Ulloa.
Forwards Alberto Paloschi, Eder and Bafetimbi Gomis have already left Swansea this summer.
Manager Francesco Guidolin admitted in July he was unsure about Ayew's future, but hoped he would stay.
Ayew suffered did not score between 2 February and 1 May which coincided with a run of two wins in 10 matches, but finished the season with four goals in three matches as Swansea finished in 12th place.
West Ham have signed striker Ashley Fletcher, midfielder Havard Nordtveit, and wingers Sofiane Feghouli and Gokhan Tore this summer.
Subscribe to the BBC Sport newsletter to get our pick of news, features and video sent to your inbox.
West Ham United have agreed a fee of about £20m to sign Ghana striker Andre Ayew from Swansea City.