I had a similiar problem. In truffel.js the networkId was set to 1337. In the Ganache GUI, too. But when I return the the chainId with the contract function
function getChainId() public view returns (uint256 chainId) {
assembly {
chainId := chainid()
}
}
then i got 1 for the chainId. I know that the networkId is not the chainId. But theres is no way to configure the chainId when using the Ganache GUI.
I could not solve the problem but it works with using the trufflesuite / ganache (https://github.com/trufflesuite/ganache) instead. When I start ganache with
ganache --chain.chainId 1337 --chain.networkId 1337
then I get 1337 as chainId with the function described above.
The Ganache started on the command line workworks as good as the Ganache GUI but it is more flexible, because there are much more possibilities to configure Ganache when starting it up.