sendAndPay
Function
Upload data and pay for storage.
Example
- Node
- Web
import { genNodeAPI } from 'arseeding-js'
const run = async () => {
const instance = await genNodeAPI('YOUR PRIVATE KEY')
const arseedUrl = '<https://arseed.web3infra.dev>'
const data = Buffer.from('need upload data ...')
const tag = '<chaintype-symbol-id>' // everpay supported all token tag (chainType-symbol-id)
const options = {
tags: [
{ name: 'Content-Type', value: 'data type' },
{ name: 'aa', value: 'aaa' }
]
}
const res = await instance.sendAndPay(arseedUrl, data, tag, options)
// If you need upload orders by sequence, you can configure the needSeq parameter to true
const res = await instance.sendAndPay(arseedUrl, data, tag, options, true)
console.log(res)
}
import { genAPI, genArweaveAPI } from 'arseeding-js'
const run = async () => {
// ethereum wallet
const instance = await genAPI(window.ethereum)
// arweave wallet
const instance = await genArweaveAPI(window.arweaveWallet)
const arseedUrl = '<https://arseed.web3infra.dev>'
const data = Buffer.from('need upload data ...')
const tag = '<chaintype-symbol-id>' // everpay supported all token tag (chainType-symbol-id)
const options = {
tags: [
{ name: 'Content-Type', value: 'data type' },
{ name: 'aa', value: 'aaa' }
]
}
const res = await instance.sendAndPay(arseedUrl, data, tag, options)
// If you need upload orders by sequence, you can configure the needSeq parameter to true
const res = await instance.sendAndPay(arseedUrl, data, tag, options, true)
console.log(res)
}
The sendAndPay function will do both the upload and the payment, so make sure your wallet has sufficient assets on the everPay Protocol. If you are using your own Arseeding node and have No_Fee mode turned on, please use the "data only" upload method for the upload process.
- Params
- Type
Field | Description |
---|---|
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. |
needSeq | If you need upload orders by sequence, you can configure the needSeq parameter to true. |
(
arseedingUrl: string
data: Buffer
tag: string
opts: DataItemCreateOptions
needSeq?: boolean
debug?: boolean
)
返回数据
- Return Example
- Return Type
{
everHash: '0xf88033873d3bfc525d9333ec51b60f3f3dc03f822a9a73f66a10ebbd944b29c6',
order: {
itemId: '2bpKpp0dtfFZE82-P0lOmeI5x4m2ynatFzdjBmCWd4k',
size: 192,
bundler: 'uDA8ZblC-lyEFfsYXKewpwaX-kkNDDw8az3IW9bDL68',
currency: 'USDC',
decimals: 6,
fee: '1141',
paymentExpiredTime: 1690702235,
expectedBlock: 1210331,
tag: 'ethereum-usdc-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
}
}
{
everHash: string
order: {
itemId: string
size: number
bundler: string
currency: string
decimals: number
fee: string
paymentExpiredTime: number
expectedBlock: number
tag: string
}
}