Let’s say I’m a blacksmith and I make and sell a sword, how would a tax collector know of the sale or the amount of money I made? How would the tax collector determine how much money I have to pay in taxes?
In general, in medieval times there were no income or sales tax and thus no incentive to sell under the table.
Revenue was generally collected through a fixed land rent (on land owners), duties (on tenants and serfs), fees (on the usage of communal or crown owned land) and tolls (on traders, burghers and merchants) and finally property tax in cities. The common denominator about these is that they are hard to avoid. You own a certain amount of land and thus owe a certain amount of land rent - paid in money or goods - yearly. This is regardless how the harvest was or your side businesses (if any, but often some kind of cash crop, which varied with time and place) performed.
Serfs or tenants would pay duties - in labour, goods or coin, for the privilege of using the land they have access to. This was usually fixed though tradition or contracts and also unrelated to the harvest or any side business performance.
Some non-farmland were communal or belonged to the crown (or a local nobleman), and the right to use it was paid with fees, that sometimes were fixed and at times a percentage of what was extracted. If you exctracted ore from the mountain, wood from the forest or fed pigs on acorns in an oak forest, you often had to pay a fee for the usage of the land and/or resources to the owner.
Tolls were extracted on roads, bridges, on rivers, in ports and at city gates to bring goods over or into places. These tolls were often extracted in coin rather than as labour or goods, which often made them very attractive to local rulers, as coin could be a scarce resource in Medieval Europe, as most taxes were paid in goods or labour.
Finally, the burghers of a town or city with city rights would in exchange for having a monopoly on trade and crafting in the city pay a tax which was also fixed, and often related to their property in the city - in some places it was for example set after the street frontage of the property, which is why you in some old cities in Europe can see very narrow and very high buildings.
So, let us presume you are a smith in Medieval Sweden, working in Stockholm. A wealthy peasant decides he wants a sword, so he travels to Stockholm to order one from you.
First of all, the wealthy peasant have paid land rents on his farmland. If he made his money on a side business, such as wool from sheep, charcoaling or tarring, chopping firewood or perhaps keeping pigs in the local oak forest, he had paid land fees for the usage of the communal, noble, church or crown owned land as well.
You agree on a price and you get to work. You get iron ingots from your regular guy on the market - you know he gets them from a couple of men running a bog iron business on the side of their farming in the Bergslagen area of Uppland. They pay a yearly fee to the local thing, which uses it to pay part of the tithing to the local parish priest and for a welfare relief fund. Some of the iron may come further northwest, from the mines run by "mountain burghers" who pay a yearly fee to the crown and bergssaten ("the mountain state/authority") to enjoy mining rights and mine the iron by putting up fires and then throwing cold water on the ore-rich rock, making it crack. Local smelteries make iron ingots which are then transported on rivers or by ox-cart (or sled in winter) down to Stockholm. On the way, the traders transporting the ingots may have to pay tolls to the local nobleman or bailiff when passing - the money is supposed to be used to maintain roads and brigdes (including wooden passageways over wetland) but may be skimmed off quite a bit, depending on how good local and central power is workign against corruption.
Once at the city walls, the merchant transporting your iron would have to pay a toll to enter the city and sell his iron ingots to you, varying with time, policies and not seldomly the corruption of the gatye guards. Later in the Medieval era, many monarchs tried to encourage trade by early mercantilistic policies, including forbidding local trade fairs and similar events and tryng to route all trade to cities where it could be properly taxed, and merchants could be incited to go because of the large amount of trade.
Likewise, the charcoal you use in your forge will also most likely come from outside the city, from a peasant who paid the local church (which owns the forest) a feww to extract older, tar-rich lumber from it and cook tar and burn charcoal from it to sell and likiewise would have been tolled both on the way and when passing the city walls.
You would smith the sword, extract payment from the wealthy peasant and save up some to pay your own yearly fees to the city for your position as a burgher and your property in the city.
As you can see, with these systems there's no need to ell udner the table, as there's no sales tax or income tax involved. Illicit business would instead be to smuggle the iron ingots past the gate guards to avoid the tolls, for the iron ore extractor to do it in secret without paying any fees or for the peasant to acquire new land but not register it for tax and thus still pay the fixed fee as if his farm was smaller than it is.
You can see why land ownership, traditional and contractual rights and how much and how these rights were to be paid for were extremely common legal issues during the Medieval period.
This answer will use England from the mid-14th century as a point of reference.
Firstly, in order to understand medieval taxation, we must differentiate it from modern forms of taxation. By the mid-14th century, England used a fixed form of taxation, which meant that each taxable county was liable for a fixed amount of money. It was up to the sheriff, and by extension, tax collectors (or tax farmers as they were often referred to) to source this amount of money from the community. The amount each county needed to pay was tallied by the Exchequer, which eventually led to the government spending money that it assumed would be taxed in the future, writing essentially cheques to be cashed in at a future point - inadvertently creating public debt. Sheriffs were under immense pressure to collect this money. A letter from Henry III warns a particularly unlucky sheriff that upon failure to collect, he faces physical, corporal punishment, the seizure of his property, and "the King's displeasure".
Prior to 1336, taxation was based on the individual. This tax was based on property, which could be inspected by the local sheriff, and was a percentage of the monetary value assessment of the person's property. This percentage varied - during the end of the 13th century, it was particularly high due to Edward I's wars.
Taxes relating to transactions, like the example mentioned in the question, seem to (to the best of my knowledge) not be based in the monetary value of the transaction itself. Instead, we must take into account several factors. Our blacksmith would, unless creating this sword on commission, have to go to a market in order to sell it. I am not sure how often the rate of commission versus sale at market is for blacksmiths, but for other merchants, the example still stands. Movable goods were taxed at different points in English history - the blacksmith's cart may be examined upon arrival, and a tax imposed based on the estimated value of the good's brought for sale. Other taxes were also levied in markets, including urban tolls for the use of the roads, fees for having a market stall, and fines for the violation of market rules. These would be taxed by local authorities - the sheriff, the lord, perhaps a local monastery (in the case of the road tolls), but would factor in to the greater tax assessment by the King.
The other way of taxing the blacksmith, in the case of commission, would remain the property tax. To avoid this, the blacksmith would have to both hide the money itself and refrain from spending it on household furnishings or smithing supplies, in order to avoid a higher assessment of his property's value, and thus, paying a higher property tax. This was made more difficult by the little availability of small coinage. Due to the difficulties in minting smaller and smaller coins (as value was based on the weight of the coin), often peasants would, for example, have to pay a full penny for a half-penny's worth of goods, and not receive the amount due back, buy the larger amount of goods, or go without. This would make transactions larger, and harder to hide. The close nature of the authorities collecting the taxes (the local sheriff, for the most part) made hiding wealth more difficult, although presumably in some instances it still happened.
Furthermore, blacksmiths can only do so much work in a day. By the time of the taxation shift to a community tax on the whole, to be levied by the local authorities, the amount of property tax to be paid, for artisans and landowners alike, became a fixed amount based on previous payments and assessments of property.
Granted, some did try to dodge the taxation process. Taxes throughout the 14th century were harsh due to England's perpetual warfare against France. Peasants increasingly went into debt to pay off their taxes, or sold possessions or essential goods such as plows or animals. Others abandoned their land and holdings to avoid taxation they could not pay. Poems such as The Song against the King's Taxes lamented the cruelty and injustice of a taxation system that was harshest on the peasantry, denouncing the parasitic nature of tax collectors as "mere robbery". Corrupt tax collectors were often the target of these poems, and certainly existed. Peasant unrest was often due to the harshness of government taxation - such as in the 1340s, when food shortages were common due to peasants selling their seeds in order to meet tax demands.
So in essence, one could certainly hide a transaction or two, but it would not have made a difference in the long-run, due to the nature of taxation being different. The motive was certainly there, as harsh taxation caused widespread resentment in England throughout the 14th century. Taxation was primarily done through a property tax based on an assessment of the value of either personal property or the land owned or leased. Taxes were also levied through fees due to importing, exporting, or selling goods at market, for the use (and presumably upkeep) of roads.
Sources:
Desan, C. Making Money: Coin, Currency, and the Coming of Capitalism. Oxford: Oxford University Press, 2014.
Saul, N. A Companion to Medieval England 1066-1485. Stroud: Tempus Publishing, 2000.