'How to send my content to a global IPFS node?
To use IPFS in NodeJS, I require ipfs module. To connect a IPFS node I try:
const IPFS=require("ipfs");
const node= await IPFS.create();
After that, When I run NodeJS in PowerShell, The below messages emerge:
Swarm listening on /ip4/192.168.1.100/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/192.168.88.1/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/192.168.49.1/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
I think the above messages are mentioning that I connected to a local IPFS node. If my thought is true, It can be because of IPFS.create(). So, I should put a gateway as an argument to that to connecting a global node. I saw some IPFS public gateways on Public Gateway Checker but I don't know how to put one sample in IPFS.create();
Please giude me:
Am I right about the messages on PowerShell?
How to use a global IPFS gateway in my code?
My whole NodeJS code:
const IPFS=require("ipfs");
async function register(){
const node=await IPFS.create();
node.add("Main Content!").then(function(ipfsHash){console.log(ipfsHash)});
}
Whole result in PowerShell:
Swarm listening on /ip4/192.168.1.100/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/192.168.88.1/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/192.168.49.1/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/12D3KooWCGvmbySrpdCVKACJPjZeeUiMR6gSQffa7W3gWZLSGBxp
{
path: 'QmUaTPt2Uus46Cgo4YMKze8PpHrCKvZ1YXD2zpffNt8U9S',
cid: CID(QmUaTPt2Uus46Cgo4YMKze8PpHrCKvZ1YXD2zpffNt8U9S),
size: 21,
mode: 420,
mtime: undefined
}
Thank you a lot!
Solution 1:[1]
When you call create(), the client connects to a local node the URL http://localhost:5001. To connect to another HTTP gateway to a global node, simply pass the gateway's URL instead.
const client = await IPFS.create("https://<your-preferred-gateway>");
const { cid } = await client.add("Your content");
See also: create options
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pandemonium |
