Frame-92.png
2022-03-24

Use goar to Store Data Permanently on Arweave

Arweave is an easy-to-use storage blockchain for permanent data storage and data reading. Unlike Filecoin, Arweave has no cumbersome ordering process; users and developers simply hold AR tokens to upload data to the Arweave network. Once the data transactions are packaged, users and developers can read and download the data at any time.

What is goar?

goar is the Arweave SDK developed by everFinance and is the official Golang version of the Arweave SDK.  goar repo is available through the Github link. Developers can also get more SDKs from the Arweave website here. The following section describes Arweave’s storage costs and how to integrate goar.

Storage Costs

Permanent storage costs more than cloud providers like AWS, but far cheaper than traditional blockchains like Ethereum, where a single transaction on Ethereum costs tens of dollars, while permanent storage on Arweave costs just $10 for 1 GB.

Use ArweaveFees to see storage costs: https://arweavefees.com/.

Prerequisite

Before developing, developers must have an Arweave wallet address and hold a certain number of ARs.

Generate AR wallet

Use the official Arweave wallet to securely generate an Arweave wallet address. You can download the official wallet by searching for Arweave in the Chrome Store.

Once the installation is complete, you can create a wallet by clicking the “Create a new wallet” button of the plugin.

The keyfile generated should be kept tightly, the keyfile is the private key of the Arweave wallet and should not be disclosed. keyfile will be used in the configuration file of goar, and the key will be injected into goar for usage.

The wallet address generated using the official Arweave wallet is shown below: 

Get AR

There are two ways to get AR. The first is to use a centralized exchange. Currently Binance, Huobi, OKX, and other exchanges list Arweave, where developers can buy ARs and withdraw them to the Arweave wallet address.

The second way to get AR is through a decentralized exchange. if a developer already has an Ethereum account and holds USDC or USDT on Ethereum, they can top-up USDC or USDT to the everPay protocol and use everPay Swap to swap for AR. Once the swap is complete, the AR can be withdrawn to the Arweave mainnet. Direct link here.

 

 

You can also purchase wAR (Wrapped AR) from Uniswap and use everPay to cross-chain WAR back to Arweave’s main network after purchase. Direct link:

How to Integrate goar

If you don’t have an Arweave wallet and AR tokens, please check the previous section.

Load Wallet

You can install goar into your own repository with the following command:

go get github.com/everFinance/goar

goar supports loading wallets from file paths:

wallet, _ := goar.NewWalletFromPath(“./keyfile.json”, “https://arweave.net”)

./keyfile.json is the wallet key file. https://arweave.net is the official Arweave gateway, or if the developer has their own node, they can configure their own.

Data Sending

Once the import is complete, use the wallet object to process the data transaction and send it.

tx, err := wallet.SendData(

  []byte(“123”), // Data bytes

  []types.Tag{

    types.Tag{

      Name:  “testSendData”,

      Value: “123”,

    },

  },

)

fmt.Println(tx.ID, err)

[]byte(“123”) is the data to be uploaded and the developer can put any binary data here for processing.

[]types.Tag is the tag for the Arweave transaction. Tags are key-value pairs of data that will be processed by Arweave.net’s GraphQL for data retrieval. Developers can define multiple tags for Arweave transactions.

The ID of an Arweave transaction can be obtained using tx.ID.

Data Downloading

The data can be downloaded using the Arweave transaction ID.

data, err := wallet.Client.GetTransactionData(id)

Local Files Uploading and Downloading

Using goar makes it easy to build data upload applications. This data can be either local data or data obtained from the API. An example of text file upload using goar can be seen in the following link:

https://github.com/everFinance/goar/blob/main/example/local_data_test.go 

FAQ

1. Transaction packaging is slow.

Arweave takes 2-10 minutes to pack and generate a block, and the transaction packing speed is slow. Arweave is slow on producing blocks, but the volume of storage is large (infinite). Arweave transactions have no block size limit, and no transaction size limit, so developers can upload larger and more files in bulk at once.

2. Packaging of transactions is not started for a long time.

It is likely that due to network congestion, the transaction will fail to pack due to fees not meeting miner demand. An Arweave transaction must be packaged within 50 blocks, and if the transaction exceeds the 50 block height after it is sent, it will be abandoned by the network and never packaged again. Transactions that remain unpacked beyond 50 blocks may be considered for resending by the developer. If the network is congested, developers can use the transaction acceleration feature to speed up transaction packing by increasing the expense of the transaction.

3. Concurrent file uploads

Unlike Ethereum, where users sending new transactions must wait for the previous transaction to be completed, Arweave can support concurrent transactions, each of which is packaged independently on Arweave.

 


Join our
Telegram / Discord / Twitter

In PSCs
Tagged with In No tags

Sign up for newsletter

Sign up here to get the latest news and updates delivered directly to your inbox.