As per documentation we have import features, but do we have any export to file feature in Solidity that I can use inside my smart contract.

Got a similar thread at How to export transactions into a CSV file but it discusses only about exporting transactions, rather than intermediate or final results of a smart contract operation.


No, this is not possible. The EVM has no access to a filesystem.

The import keyword is used at contract compile time, in your local build environment. It imports Solidity code ahead of creating the smart contract. It does not form part of the compiled contract and is not executed on the blockchain (in the EVM).

Once the contract has been deployed, it runs only in the Ethereum Virtual Machine (EVM) and can neither read nor write files.

Instead, contracts have two ways to record output.

  1. For ephemeral results that the contract does not need to store, you can issue Events to log limited amounts of data. These logs can be queried later using blockchain explorers or other tools.

  2. Contract state that needs to be maintained can be placed in contract Storage and queried later (using getter functions, which Solidity can automatically generate for you). This is relatively more expensive in gas terms than events.

Remember that the contract after deployment will be run on thousands of nodes worldwide. It currently doesn't make much sense to think of a conventional filesystem in these terms. Perhaps in future there may be a way for the EVM to interact with Swarm (a fully distributed filesystem). But that would be a long way off from now.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.