Our objective is to estimate the C/O ratio in the atmosphere of beta Pictoris b and obtain an estimate of the dynamical mass of the planet, as well as to refine its orbital parameters using high-precision astrometry. We used the GRAVITY instrument with the four 8.2 m telescopes of the Very Large Telescope Interferometer to obtain K-band spectro-interferometric data on $beta$ Pic b. We extracted a medium resolution (R=500) K-band spectrum of the planet and a high-precision astrometric position. We estimated the planetary C/O ratio using two different approaches (forward modeling and free retrieval) from two different codes (ExoREM and petitRADTRANS, respectively). Finally, we used a simplified model of two formation scenarios (gravitational collapse and core-accretion) to determine which can best explain the measured C/O ratio. Our new astrometry disfavors a circular orbit for $beta$ Pic b ($e=0.15^{+0.05}_{-0.04}$). Combined with previous results and with Hipparcos/GAIA measurements, this astrometry points to a planet mass of $M = 12.7pm{}2.2,M_mathrm{Jup}$. This value is compatible with the mass derived with the free-retrieval code petitRADTRANS using spectral data only. The forward modeling and free-retrieval approches yield very similar results regarding the atmosphere of beta Pic b. In particular, the C/O ratios derived with the two codes are identical ($0.43pm{}0.05$ vs $0.43^{+0.04}_{-0.03}$). We argue that if the stellar C/O in $beta$ Pic is Solar, then this combination of a very high mass and a low C/O ratio for the planet suggests a formation through core-accretion, with strong planetesimal enrichment.