Skip to main content

Deep Guide

The above article describes how to use web3infra.dev to permanently store files. Developers can use the sdk to connect to the official everFinance deployment of web3infra for file storage, or they can deploy their own arseeding light nodes.

Compare web3infra and private nodes

web3infra

  • No need to configure Arweave wallets, no need to hold AR
  • Compatible with Ethereum addresses and Arweave addresses
  • Must have assets on everPay and use assets on everPay for payments

Private Node

  • Need to configure Arweave wallet and hold AR
  • Option to turn payments on or off
  • Calling the ANS-104 interface will consume the AR in the configured Arweave wallet

Deploy Private node please reference:

Deploy Light Node

Workflow Logic

web3infra

  1. The developer uploads the data (file) to the Arseeding node via the Item format of ANS-104.
  2. Arseeding node will return an everPay order
  3. The developer pays for the stored order using everPay
  4. Arseeding will receive the payment record and change the data status to be sent
  5. Arseeding uploads the data to Arweave Network via ANS-104 batch.

As shown in the figure below:

Note: If the developer does not pay for the order, the data cache will be deleted from the Arseeding node after one hour.

Private Node

The process for the private node is similar to web3infra, if the payment feature is turned off, the process is as follows:

  1. The developer uploads the data (files) to the Arseeding node via ANS-104 in Item format.
  2. Arseeding uploads the data to Arweave Network via ANS-104 in batch.

Note: Arseeding with payments turned off will receive data from any user and automatically complete the Arweave Network data upload. You may need to implement additional interface authentication functionality, or make the interface available only to internal services for use.

About Guide

This guide will provide an in-depth look at three different ways to interact with the web3infra service for file storage. They are:

  • Data upload and automatic payment: just use one method to do data upload and payment of fees.
  • Decoupled data upload and fee payment: Handle the data upload and fee payment methods separately. This is suitable for application scenarios where the fee payment private key and the data signature private key are not the same.
  • Submit data directly using apiKey: Submit the original data directly using apikey authentication, This is suitable for scenarios that do not need to sign and pay for the data, but just want to use the simplest way to store the data forever .

Installation

Make sure you already have knowledge of front-end or node.js, and install arseeding-js in the terminal using the following command:

npm i arseeding-js

Data Upload And Automatic Payment

Wallet Initialization

Web3 has two wallet initialization options, either injecting MetaMask or ArConnect on the web side via the Provider, or injecting the key directly in the local node-js.

  1. Local key injection

This method is available for node-js development.

Ethereum Wallet

import { genNodeAPI } from 'arseeding-js'
const instance = await genNodeAPI('<YOUR PRIVATE KEY>')

Arweave Wallet

TODO

2. Web3 Provider

This method is suitable for Browser development.

MetaMask

import { genAPI } from 'arseeding-js'
const instance = await genAPI(window.ethereum)

ArConnect

TODO

Data Uploading And Paying

Simply use the instance.sendAndPay method to complete the data upload and fee payment.

const arseedUrl = '<https://arseed.web3infra.dev>'
const data = Buffer.from('need upload data ...')
const payCurrency = 'USDC' // everpay supported all tokens,like 'AR','ETH','USDT' and so on
const ops = {
tags: [
{name: "Content-Type",value:"data type"},
{name: "aa",value:"aaa"}
]
}
const resp = await instance.sendAndPay(arseedUrl, data, payCurrency, ops)
  • arseedUrl: You can use https://arseed.web3infra.dev or replace it with your own deployed Arseeding node url.
  • payCurrency: Specify the token for payment, support using any token on everPay for payment.
  • tags: tag the uploaded data, you can tag it with many tags as you want. Note: The data must have a Content-Type tag to describe the data type, so that the data can be rendered directly by the browser. What are 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.

Decoupled Data Upload And Fee Payment

To meet more storage application scenarios, Arseeding-js provides decoupled usage of data upload and fee payment. This means that developers can pay for storage on behalf of users, e.g., the national library uploads literature data to the Arseeding node, and Arweave Org checks for data uploads from the library and makes storage payments on behalf of the national library.

Data signing and uploading

1.Signing for data uploading

Uploading data requires signing the data with a private key. Arseeding-js supports the following three signature providers:

  • MetaMask signature (for Browser development)
  • ECC private key signature
  • RSA private key signature

1.1 MetaMask

This method will sign the data using MetaMask.

import { providers } from 'ethers'
import getCurrency from 'bundlr-arseeding-client/build/web/currencies'

const provider = new providers.Web3Provider(windowEthereum)
await provider._ready()
const currencyConfig = getCurrency('ethereum', provider)
await currencyConfig.ready()
const signer = await currencyConfig.getSigner()

We have implemented the MetaMask upload data Demo: demo.web3infra.dev , source code: https://github.com/everFinance/arseed-bundle-demo.

1.2 ECC private key

This approach is suitable for scenarios where the nodejs service is configured with a private key of type ecc specifically for signing.

import EthereumSigner from 'arseeding-arbundles/src/signing/chains/ethereumSigner'

const privateKey = '<your ecc private key>'
const signer = new EthereumSigner(privateKey)

1.3 RSA private key

This approach is suitable for scenarios where the nodejs service is configured with a private key of type rsa specifically for signing.

import ArweaveSigner from "arseeding-arbundles/src/signing/chains/ArweaveSigner"

const wallet = JSON.parse(
readFileSync(path.join(__dirname, "test_key.json")).toString(),
);
const signer = new ArweaveSigner(wallet)

2. Signing and uploading

Assemble the data into a bundle Item and sign the data using the signer generated above and upload it to Arseeding.

const data = Buffer.from('<need upload data>')
const ops = {
tags: [
{ name: 'key01', value: 'val01' },
{ name: 'Content-Type', value: 'imag/png' } // you should set the data type tag
]
}
const arseedingUrl = '<https://arseed.web3infra.dev>'
const payCurrency = 'USDC' // everpay supported all tokens, like 'AR','ETH','USDT' and so on
const order = await createAndSubmitItem(arseedingUrl, signer, data, ops, payCurrency)
  • arseedUrl: You can use https://arseed.web3infra.dev or replace it with your own deployed Arseeding node url.
  • payCurrency: Specify the token for payment. everPay supports any token on everPay for payment.
  • tags: tag the uploaded data, you can tag it as many times as you want. Note: The data must have a Content-Type tag to describe the data type, so that the data can be rendered directly by the browser. What are tags.

Example of order’s return value:

{
itemId: 'XTnZ26gmangoxn7BBXXXabZhxf-BQgnI-x8p1xNUDdA',
bundler: 'uDA8ZblC-lyEFfsYXKewpwaX-kkNDDw8az3IW9bDL68',
currency: 'USDC',
decimals: 6,
fee: '28029',
paymentExpiredTime: 1658827438,
expectedBlock: 982398
}

Fee Payment

Arseeding only supports everpay payment channel, so you must ensure that the address has enough token balance on everPay Protocol to pay for the stored orders before paying for the uploaded orders. everPay asset top-up can be found here.

1. everPay supported signing method

everPay supports the following three signing methods.

1.1 MetaMask

This method generally involves signing the everPay transaction using a metamask on the client side.

import { providers } from 'ethers'
import Everpay from 'everpay'

const provider = new providers.Web3Provider(windowEthereum)
await provider._ready()
const accounts = await provider.listAccounts()
const account = accounts[0] ?? ''
const everpay = new Everpay({
debug: debug,
account: account,
ethConnectedSigner: provider.getSigner(),
chainType: 'ethereum' as any
})

1.2 ECC private key injection

This method is suitable for nodejs services configured with an ecc type private key specifically to send everPay transactions for payment fees.

import { newEverpayByEcc } from 'arseeding-js'

const eccPrivate = '<your ecc private key>'
const everpay = newEverpayByEcc(eccPrivate)

1.3 RSA private key injection

This method is suitable for nodejs services configured with a private key of type rsa specifically for sending everPay transactions with payment fees.

import { newEverpayByRSA } from 'arseeding-js'

const arJWK = '<your arweave wallet keyFile>'
const arAddress = '<your arweave wallet address>'
const everpay = newEverpayByRSA(arJWK, arAddress)

2. Use everpay to pay for your order

import { payOrder } from 'arseeding-js'
const everHash = await payOrder(everpay, order)
  • order: the order’s return value for the uploaded data
  • everHash: everPay tx hash for payment

Code Example

  1. Data uploaded but fee not payed: https://github.com/everFinance/arseeding-js/blob/main/example/uploadFile.ts
  2. Pay for data order: https://github.com/everFinance/arseeding-js/blob/main/example/payBill.ts

Submit data using apiKey

Arseeding supports authorizing clients to submit data to the server via apikey, which has the advantage that the client does not need to sign the data with a private key. There is no need to use everPay to pay for the data.

The Arseeding node receives the data, assembles the signed bundle item with its own private key and sends it to the server.

const arseedingUrl = '<https://arseed.web3infra.dev>'
const apikey = '<your arseeding apiKey>'
const data = '<need upload data, such as a picture>'
const contentType = 'image/png'
const tags = {'a':'aa','b':'bb'}
const res = await submitByApikey(arseedingUrl,apikey,data,contentType, tags)
  • apiKey: Apply for apiKey
  • contentType: data type, used to get the data directly rendered in the browser.

Code Example

https://github.com/everFinance/arseeding-js/blob/main/example/apiKey.ts