Created
          January 9, 2023 20:07 
        
      - 
      
- 
        Save stevedylandev/198e8345d203035b2a4a6531f1b7cf69 to your computer and use it in GitHub Desktop. 
    A Pinata API call that will pin a string to IPFS
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const { Readable } = require('stream'); | |
| const FormData = require('form-data') | |
| const axios = require('axios'); | |
| const JWT = 'Bearer PASTE_YOUR_PINATA_JWT' | |
| const pinStringToIPFS = async (string) => { | |
| try { | |
| const buffer = Buffer.from(string, 'utf8') | |
| const stream = Readable.from(buffer) | |
| const data = new FormData() | |
| data.append('file', stream, { | |
| filepath: "string.txt" | |
| }) | |
| const res = await axios.post("https://api.pinata.cloud/pinning/pinFileToIPFS", data, { | |
| headers: { | |
| 'Authorization': JWT | |
| } | |
| }) | |
| console.log(res.data) | |
| } catch (error) { | |
| console.log(error) | |
| } | |
| } | |
| pinStringToIPFS("Hello World!!") | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment