-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mint NFT with IPFS storage
- Loading branch information
Samuel Sramko
committed
Aug 17, 2021
1 parent
4881be8
commit f0b9d7c
Showing
14 changed files
with
416 additions
and
271 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ipfs'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {readFileSync} from 'fs'; | ||
import {ipfsUpload} from './ipfs'; | ||
|
||
describe('IPFS storage', () => { | ||
|
||
jest.setTimeout(99999); | ||
it('should store IPFS record', async () => { | ||
await ipfsUpload(readFileSync('/Users/ssramko/Downloads/logo_tatum.png'), 'logo_tatum.png'); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import { get, upload, httpDelete } from '../connector/tatum' | ||
import FormData from 'form-data'; | ||
import {get, httpDelete, postMultiForm} from '../connector/tatum'; | ||
|
||
/** | ||
* Stores file on the IPFS. This operation is available only for paid plans. | ||
* For more details, see <a href="https://tatum.io/apidoc#operation/StoreIPFS" target="_blank">Tatum API documentation</a> | ||
*/ | ||
|
||
export const ipfsUpload = async (file: Buffer): Promise<{ ipfsHash: string }> => upload(`/v3/ipfs`, { file: Uint8Array.from(file) },) | ||
/** | ||
* Upload file to the IPFS storage. | ||
* @param file Data buffer of the file | ||
* @param fileName Name of the file to upload. | ||
*/ | ||
export const ipfsUpload = async (file: Buffer, fileName: string): Promise<{ ipfsHash: string }> => { | ||
const body = new FormData(); | ||
body.append('file', file, fileName); | ||
return await postMultiForm('/v3/ipfs', body); | ||
}; | ||
/** | ||
* Gets data from the IPFS. Every 100 kB of data costs 1 additional credit. | ||
* For more details, see <a href="https://tatum.io/apidoc#operation/StoreIPFS" target="_blank">Tatum API documentation</a> | ||
*/ | ||
export const ipfsGet = async (id: string): Promise<any> => get(`/v3/ipfs/${id}`) | ||
export const ipfsGet = async (id: string): Promise<any> => get(`/v3/ipfs/${id}`); | ||
/** | ||
* Unpin the data from the IPFS. After this operation, credits won't be charged for a storage, but file will keep exists on the IPFS. | ||
* For more details, see <a href="https://tatum.io/apidoc#operation/StoreIPFS" target="_blank">Tatum API documentation</a> | ||
*/ | ||
export const ipfsDelete = async (id: string): Promise<any> => httpDelete(`/v3/ipfs/${id}`) | ||
export const ipfsDelete = async (id: string): Promise<void> => httpDelete(`/v3/ipfs/${id}`); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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