Closed johnbailon closed 2 years ago
Hello, trying to upload a file and I seem to be hitting this error:
$ go run main.go Tx data size: 0.004551MB uplaodTx; body: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Bad Request</pre> </body> </html> , status: 400, txId: -lmcTK9yzneKUOt4_xqC3vxEH50DhhaWzYBTDDOFpCM 0.000000% completes, 0/1 2021/10/14 17:33:22 -lmcTK9yzneKUOt4_xqC3vxEH50DhhaWzYBTDDOFpCM
Code:
package main import ( "fmt" "io/ioutil" "log" "github.com/everFinance/goar" "github.com/everFinance/goar/types" "github.com/everFinance/goar/utils" ) const ARWEAVE_NODE = "https://arweave.net" func main () { data, err := ioutil.ReadFile("./test.png") if err != nil { panic(err) } tx, err := UploadToArweave("./arweave-key.json",data) if err != nil { panic(err) } log.Println(tx) } func UploadToArweave(walletPath string, data []byte) (string, error) { // Load wallet w, err := goar.NewWalletFromPath(walletPath, ARWEAVE_NODE) if err != nil { return "", err } log.Println(w.Address) // Get anchor anchor, err := w.Client.GetTransactionAnchor() if err != nil { return "", err } // Get reward reward, err := w.Client.GetTransactionPrice(data, nil) if err != nil { return "", err } // Craft tx speedFactor := int64(50) tx := &types.Transaction{ Format: 2, Target: "", Quantity: "0", Tags: utils.TagsEncode([]types.Tag{ types.Tag{ Name: "Content-Type", Value: "image/png", }, }), Data: utils.Base64Encode(data), DataSize: fmt.Sprintf("%d", len(data)), Reward: fmt.Sprintf("%d", reward*(100+speedFactor)/100), LastTx: anchor, } if err = utils.SignTransaction(tx, w.PrvKey); err != nil { return "", err } // Upload uploader, err := goar.CreateUploader(w.Client, tx, nil) if err != nil { return "", err } err = uploader.Once() if err != nil { return "", err } return tx.ID, nil }
What could be wrong here? hello, your 'Craft tx' is incorrect, the first error is your tx is not set tx.Owner. so this tx send to arweave node failed.btw, goar wallet has some api interface to send data: wallet.SendData() or wallet.SendDataSpeedUp()
you also view goar example test and you can know how to assemble a arweave tx. https://github.com/everFinance/goar/blob/main/example/chunks_tx_test.go#L73
hi @zyjblockchain, thanks for pointing out wallet.SendData()
. I was actually using the code example here and I thought it should work off the bat. Cheers.
hi @zyjblockchain, thanks for pointing out
wallet.SendData()
. I was actually using the code example here and I thought it should work off the bat. Cheers.
ohh, I am so sorry about readme example code error. now I am going to fix it thanks use goar to build arweave off-chain application goar is runing our everpay server, so you can use it safely.
hi @zyjblockchain, thanks for pointing out
wallet.SendData()
. I was actually using the code example here and I thought it should work off the bat. Cheers.ohh, I am so sorry about readme example code error. now I am going to fix it thanks use goar to build arweave off-chain application goar is runing our everpay server, so you can use it safely.
No worries, all good. Thanks for your work on this!
Hello, trying to upload a file and I seem to be hitting this error:
Code:
What could be wrong here?