Dear all
I have been playing with Stellar to see how to issue tokens.
See below code derived from the guide.
I have 3 questions though.
1. how do you limit the issuance of the token to a certain number? e.g. 5000. There is no method in the Asset class for that.
2. ho do you check the balance of the issuer to see how many of the new tokens are left? query the balance of the receiver shows the transferred asset but doesn't show anything on the issuer.
3. how do you set an unlimited amount into trustline for the receiver? the string cannot be left blank
ChangeTrustOperation.Builder(newToken, "1000")
code below:
package com.singularck.stelllar.test;
import java.io.IOException;
import org.stellar.sdk.Asset;
import org.stellar.sdk.ChangeTrustOperation;
import org.stellar.sdk.KeyPair;
import org.stellar.sdk.Network;
import org.stellar.sdk.PaymentOperation;
import org.stellar.sdk.Server;
import org.stellar.sdk.Transaction;
import org.stellar.sdk.responses.AccountResponse;
public class IssueAsset {
/*
* First account - issuer
* Secret Key: SDVWIL4T2JOTQK4DLRBTIQFUXA5OBIJE4D2DS4REYZNSSRZCXD3N5JFB
* AccountID: GCKYNRYNAXG2HPIWSQBXU5H4VP2PLQUTDVJ6MHOO7PTJBU34V7UDCUAZ
*
* Second account - receiver
* Secret Key: SBYAOEQ7ZRDF2WWP5KGFPVF5G46G5QQI6GFLAEZR6A56KQ736VFEJCJR
* AccountID: GB4IN33UP27VMSKR575P6KPHWKJLFW77OCM7KLHJIIL37BZNQI7WEV4Q
*/
KeyPair issuingKeys = KeyPair.fromSecretSeed("SDVWIL4T2JOTQK4DLRBTIQFUXA5OBIJE4D2DS4REYZNSSRZCXD3N5JFB");
KeyPair receivingKeys = KeyPair.fromSecretSeed("SBYAOEQ7ZRDF2WWP5KGFPVF5G46G5QQI6GFLAEZR6A56KQ736VFEJCJR");
Server server;
Asset newToken;
/**
* def constructor decides the network to us
*/
public IssueAsset() {
// TODO Auto-generated method stub
Network.useTestNetwork();
server = new Server("https://horizon-testnet.stellar.org");
newToken = Asset.createNonNativeAsset("IGEOTISS", issuingKeys);
// how do i limit the issuance?
}
/**
* trust to be created between the receiving account and the issuing acccoun
* the receiving account has to trust the issuing account
*/
public void accountsTrustlines() {
// First, the receiving account must trust the asset
AccountResponse receivingAccount;
try {
receivingAccount = server.accounts().account(receivingKeys);
Transaction allowNewToken = new Transaction.Builder(receivingAccount)
.addOperation(
// The `ChangeTrust` operation creates (or alters) a trustline
// The second parameter limits the amount the account can hold
new ChangeTrustOperation.Builder(newToken, "1000").build())
.build();
allowNewToken.sign(receivingKeys);
server.submitTransaction(allowNewToken);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
/**
* send stocks from the issuer account (the individual creating his own stock, to the receiving account)
* when this happens presumably concurrently the receiving account is sending G to the issuer in exchange
*/
public void sendToken() {
// the issuing account actually sends a payment using the asset
try {
AccountResponse issuing = server.accounts().account(issuingKeys);
Transaction sendNewToken = new Transaction.Builder(issuing)
.addOperation(
new PaymentOperation.Builder(receivingKeys, newToken, "137").build())
.build();
sendNewToken.sign(issuingKeys);
server.submitTransaction(sendNewToken);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
/**
* main
*/
public static void main(String[] args) {
// init
IssueAsset ia = new IssueAsset();
// receiving account trusts the issuing account
ia.accountsTrustlines();
// issuing account send the individual stocks ( presumably in exchange of G - currency of the server )
ia.sendToken();
}
}