zackbalbin / ergotutorials Goto Github PK
View Code? Open in Web Editor NEWDevelopers tutorials for the Ergo Platform
Developers tutorials for the Ergo Platform
This is all happening on testnet.
I'm following the MintToken example but am unable to run it successfully. Here's a breakdown of the situation:
To begin with, here's the part of the original code that:
val senderProver = BoxOperations.createProver(ctx, mnemonic)
val sender = senderProver.getAddress
val unspent = ctx.getUnspentBoxesFor(sender)
val boxesToSpend = BoxOperations.selectTop(unspent, totalToSpend)
Without any modifications, this part of the code did not work for me. Calling senderProver.getAddress
returned the wrong address.
So calling ctx.getUnspentBoxesFor(sender)
was returning 0 boxes.
Because of this, the call to BoxOperations.selectTop(unspent, totalToSpend)
threw the following error:
Exception in thread "main" java.lang.RuntimeException: Not enough funds in boxes to pay 1000000 nanoERGs,
tokens: [],
reason: NotEnoughErgsError(not enough boxes to meet ERG needs 1000000 (found only 0))
at org.ergoplatform.appkit.BoxSelectorsJavaHelpers$.selectBoxes(BoxSelectorsJavaHelpers.scala:31)
at org.ergoplatform.appkit.BoxSelectorsJavaHelpers.selectBoxes(BoxSelectorsJavaHelpers.scala)
at org.ergoplatform.appkit.BoxOperations.selectTop(BoxOperations.java:27)
at org.ergoplatform.appkit.BoxOperations.selectTop(BoxOperations.java:20)
at minttoken.MintToken$.$anonfun$mintToken$1(MintToken.scala:31)
at org.ergoplatform.appkit.RestApiErgoClient.execute(RestApiErgoClient.java:42)
at minttoken.MintToken$.mintToken(MintToken.scala:20)
at minttoken.MintToken$.main(MintToken.scala:69)
at minttoken.MintToken.main(MintToken.scala)
In order to get the correct address, I had to modify the code like this.
val senderProver: ErgoProver = ctx.newProverBuilder
.withMnemonic(
SecretString.create(nodeConfig.getWallet.getMnemonic),
SecretString.create(nodeConfig.getWallet.getPassword))
.withEip3Secret(addressIndex)
.build()
val sender = senderProver.getEip3Addresses.get(0) // this now returns the expected address
val unspent = ctx.getUnspentBoxesFor(sender)
val boxesToSpend = BoxOperations.selectTop(unspent, totalToSpend)
After this change:
3WwBpgxoiMKoHrk67HcquMUdGWKovAynL8tUjZWuFp9fjcbussTr
(expected) and no longer 3WwMXXodDKsrZan8C9AuYAuaHQZtoQkn1m87dnWrxR558RxLHVmu
(unexpected)unspent
is no longer emptyBut for some reason, the call to BoxOperations.selectTop(unspent, totalToSpend)
then failed with the following error:
Exception in thread "main" java.lang.RuntimeException: Not enough funds in boxes to pay 1000000 nanoERGs,
tokens: [],
reason: NotEnoughCoinsForChangeBoxesError(Not enough ERG 0 to create 1 change boxes,
for Stream(Map(0f4beaca4ecc35761bc1fa4afae2fcd62cf6b82b1722f4288c992201287fb792 -> 1)))
at org.ergoplatform.appkit.BoxSelectorsJavaHelpers$.selectBoxes(BoxSelectorsJavaHelpers.scala:31)
at org.ergoplatform.appkit.BoxSelectorsJavaHelpers.selectBoxes(BoxSelectorsJavaHelpers.scala)
at org.ergoplatform.appkit.BoxOperations.selectTop(BoxOperations.java:27)
at org.ergoplatform.appkit.BoxOperations.selectTop(BoxOperations.java:20)
at minttoken.MintToken$.$anonfun$mintToken$1(MintToken.scala:41)
at org.ergoplatform.appkit.RestApiErgoClient.execute(RestApiErgoClient.java:42)
at minttoken.MintToken$.mintToken(MintToken.scala:20)
at minttoken.MintToken$.main(MintToken.scala:70)
at minttoken.MintToken.main(MintToken.scala)
A different error this time. Reading it gave me a hunch it may have something to do with the amount of boxes and their respective values in my wallet. So I sent myself 10 ERG, ran it again, and the Not enough ERG 0 to create 1 change boxes
was gone.
Great (I thought). But now, even through the code throws no exception, and the tx's JSON payload is logged in the console, I find that the tx is not actually making it into the mempool. I then ran this FreezeCoin example, and the tx made it to the mempool, and was confirmed a couple mins later!
At this point I wasn't really sure what to do so I turned to the Ergo Platform Discord hoping to find an answer in the chat history. That's when I found this message by MrStahfelge, in response to someone who was dealing with the same situation: txs were being submitted, 200 Status Code responses were being returned, but tx never made it to the mempool:
Transaction/send doesn't make a complete check, therefore accepts transactions that are discarded before entering mempool
BlockchainContext.sendTransaction
appears to submit txs through the POST /transactions
endpoint rather than through POST /wallet/transaction/send
, but I'm seeing the same behavior: successful response (no exception thrown), tx id returned, and signed txJson payload logged to the console, BUT tx does not appear in mempool.
It doesn't seem like appkit supports a method for checking txs against the POST /transactions/check
endpoint... Alternatively I could just build a simple console app that doesn't use appkit and simply triggers HTTP requests against the node's REST API... But I'm trying to use appkit.
With all that said... has anyone been able to successfully run this example? As mentioned, I couldn't make it past certain parts of the code without making some modifications. To be honest, I'm trying to understand why I needed to make those changes in the first place. Has the example code perhaps become outdated? Or is there something wrong with my configuration? I've looked over it and everything seems correct. But even after being able to get the right wallet address from the prover, I am now facing this "silent failure".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.