createAndSubmitItem
Function
Upload data and pay for storage.
Example
- Node
- Web
import { EthereumSigner, ArweaveSigner } from 'arseeding-js'
import { createAndSubmitItem } from 'arseeding-js/cjs/submitOrder'
import { readFileSync } from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { Config } from 'arseeding-js/cjs/types'
const run = async () => {
// use ecc signer
const privateKey = '<your ecc private key>'
const signer = new EthereumSigner(privateKey)
// or
// or use rsa signer
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const wallet = JSON.parse(
readFileSync(path.join(__dirname, '<your arweave keyfile>.json')).toString()
)
const signer = new ArweaveSigner(wallet)
const data = Buffer.from('<need upload data, such as a picture>')
const options = {
tags: [
{ name: 'key01', value: 'val01' },
{ name: 'Content-Type', value: 'data type' } // you should set the data type tag
]
}
const arseedingUrl = 'https://arseed.web3infra.dev'
const tag = '<chaintype-symbol-id>' // everpay supported all token tag (chainType-symbol-id)
const config: Config = {
signer: signer,
path: '',
arseedUrl: arseedingUrl,
tag: tag
}
const order = await createAndSubmitItem(data, options, config)
console.log(order)
}
import { InjectedEthereumSigner, InjectedArweaveSigner } from 'arseeding-js'
import { createAndSubmitItem } from 'arseeding-js/cjs/submitOrder'
import { Config } from 'arseeding-js/cjs/types'
import { ethers } from 'ethers'
const run = async () => {
const data = Buffer.from('<need upload data, such as a picture>')
// ethereum
const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = new InjectedEthereumSigner(provider)
await signer.sign(data)
// or
// arweave
const signer = new InjectedArweaveSigner(window.arweaveWallet)
const data = Buffer.from('web test createSubmitArweave')
await signer.sign(data)
const options = {
tags: [
{ name: 'key01', value: 'val01' },
{ name: 'Content-Type', value: 'data type' } // you should set the data type tag
]
}
const arseedingUrl = 'https://arseed.web3infra.dev'
const tag = '<chaintype-symbol-id>' // everpay supported all token tag (chainType-symbol-id)
const config: Config = {
signer: signer,
path: '',
arseedUrl: arseedingUrl,
tag: tag
}
const order = await createAndSubmitItem(data, options, config)
console.log(order)
}
createAndSubmitItem
: will upload data. If you use the Arseeding service provided by web3infra, you need to pay for the response order, otherwise the data will clear after 60 minutes. Once the payment is made, web3infra will 100% guarantee the upload of this data to the Arweave network.
If you turn on No_Fee mode using your own node, no additional payment work is required.
- Params
- Type
Field | Description |
---|---|
signer | signer instance created by using the Ethereum private key or Arweave Key File. |
arseedingUrl | arseedUrl is the address of the Arseeding backend service that needs to be configured. Here we use the Arseed service provided by permadao at https://arseed.web3infra.dev. |
data | The data data that needs to be uploaded. |
tag | If your MetaMask address holds usdc in everPay, you can obtain the token tag for tokens that require payment fees by calling getTokenTagByEver('usdc') . Please refer to getTokenTagByEver for detailed instructions on how to use it. |
options | In ops you can configure your Arweave Tags, Arweave Tags refer to: here. |
tags | Content-Type in tags needs to be configured based on the content you upload. For example, if you upload an image in png format, configure it as image/png . For details, refer to Content-Type. |
config | If you want the order to be sequentially wound you can configure the needSeq parameter in the config to be true, the default is false. |
interface Config {
signer: Signer
path: string
arseedUrl: string
tag: string
apiKey?: string
needSeq?: boolean
}
(
data: Buffer
options: DataItemCreateOptions
config: Config
)
Return Data
- Return Example
- Return Type
{
itemId: 'b9qf5fCDY0dB-nF3ixPqL6pHVPFLiDvNYBm_MOi4yq4',
size: 203,
bundler: 'uDA8ZblC-lyEFfsYXKewpwaX-kkNDDw8az3IW9bDL68',
currency: 'USDC',
decimals: 6,
fee: '1247',
paymentExpiredTime: 1691058571,
expectedBlock: 1213090,
tag: 'ethereum-usdc-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
}
{
itemId: string
size: number
bundler: string
currency: string
decimals: number
fee: string
paymentExpiredTime: number
expectedBlock: number
tag: string
}