While the title pretty much sums up the question, let's go into a bit more detail.

It would be very useful for a number of use cases if a function in a contract could directly upload to IPFS, Swarm, or similar and retrieve the hash. (This is separate from asking about smart contracts having access to a local file system - we can assume here that the data is passed to the function directly as an argument.) Theoretically you could even have a gateway contract that does this as a feature - hit the function on the contract and it returns a hash.

One easy use case is in the NFT world. NFTs have metadata explaining what they are tokenizing. To date, as far as I know, those who go with storing the metadata off-chain generate the metadata off-chain, maybe just storing a provenance hash in the contract to prove the veracity of the metadata. Alternatively some projects opt to store metadata on-chain, particularly generative NFTs. (Here's a nice thread talking about different approaches to metadata storage.)

But what if an on-chain function could upload to IPFS or similar and retrieve the hash? I would think this would open up a lot of interesting options. On the other hand, I can't find anything like this. Is it impossible or prohibitively hard? What are the difficulties, and what would need to be done to make it work?

(I'll tag Solidity simply because for many Solidity is synonymous with smart contracts, but the question applies equally to any other smart contract language.)


2 Answers 2


It would be very useful for a number of use cases if a function in a contract could directly upload to IPFS, Swarm, or similar and retrieve the hash.

It would be useful, but what you are asking is impossible in computer science theory, and practice.

Ethereum, like all other blockchains, is deterministic. They cannot communicate with any off-chain resources, because the blockchain would be no longer deterministic - any node, miner, etc. could get a different reply from an IPFS node.

  • this might be my misunderstanding, but isn't the IPFS content hash also deterministic? Commented Aug 20, 2021 at 12:45
  • 1
    Yes, but whether any read or write operation with IPFS success is not. Commented Aug 20, 2021 at 13:53
  • 1
    shouldn't it still be possible to create a kind of orcale/bridge - a dedicated contract that is trusted to upload to IPFS and return a hash? Commented Aug 22, 2021 at 8:58
  • I'm going to accept this answer in the meantime, just for providing the bit about determinism. I would still love an answer with more detail about what an oracle for this might look like, or if that is impossible, and even with an explanation about the determinism - is content hashing in IPFS completely nondeterministic? Commented Aug 26, 2021 at 13:23
  • Oracle networks themselves have some sort of system to vote on oracle responses. Or at least they should have. But unlike Ethereum if some particular oracle system fails to be determinstic, it is not a threat to the whole network. Only its users will suffeer. Commented Aug 26, 2021 at 15:25

The Ethereum blockchain is an entirely separate system from IPFS, it does not understand what IPFS is or what it does. In most DApps, what usually happens is that the file is uploaded to IPFS via the UI, and then the resulting IPFS hash is fed to the smart contract as a string for on-chain storage and aggregation. That should be enough to cover most applications.

  • Thanks for the answer! I understand what the usual flow is, I'm wondering if it's possible to do one better and have an on-chain process for uploading to them. Swarm used to be packaged inside the Geth architecture, it seems like it should be possible. Commented Aug 22, 2021 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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