Brord

Accound send examples

Apr 9th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1.         String network = "nodes.devnet.iota.org";
  2.         int port = 443;
  3.            
  4.         IotaAPI api = new IotaAPI.Builder()
  5.                 .host(network)
  6.                 .port(port)
  7.                 .protocol("https")
  8.                 .timeout(500)
  9.                 .localPoW(new PearlDiverLocalPoW())
  10.                 .build();  
  11.        
  12.         String seed = "9999999999TESTSEED9999999";
  13.        
  14.         IotaAccount account = new IotaAccount.Builder(seed)
  15.                 .api(api)
  16.                 .securityLevel(2)
  17.                 .mwm(14)
  18.                 .store(new AccountFileStore("account.store"))
  19.                 .build();
  20.         ConditionalDepositAddress address = account.newDepositAddress(new Date(Long.MAX_VALUE), true, 0).get();
  21.        
  22.         // nextZeroValueAddress fails when we dont have a deposit address made, ever
  23.         // Both The message and the tag are optional, and can be null (default messages to "IOTA Accounts Transfer")
  24.         Future<Bundle> bundle = account.sendZeroValue("Hello!", "COOL9TAG", address.getDepositAddress().getHashCheckSum());
  25.         bundle.get();
  26.  
  27.         // Calling send with 0 value, will act the same as sendZeroValue
  28.         Future<Bundle> bundle = account.send(address.getDepositAddress().getHashCheckSum(), 0, "Hello!", "COOL9TAG");
  29.         bundle.get();
  30.  
  31.         // Sweep the entire account to 1 address
  32.         Date n = new Date(System.currentTimeMillis() + 1000 * 60 * 60);
  33.         ConditionalDepositAddress address = account.newDepositAddress(n, false, account.usableBalance()).get();
  34.  
  35.         Future<Bundle> bundle = account.send(
  36.                 address.getDepositAddress().getHashCheckSum(),
  37.                 address.getRequest().getExpectedAmount(),
  38.                 Optional.of("Sweep of all addresses"), Optional.of("IOTA9SWEEP"));
  39.         bundle.get();
  40.  
  41.         // Or accept a CDA
  42.         String magnet = "";
  43.         ConditionalDepositAddress cda = DepositFactory.get().parse(magnet, MagnetMethod.class);
  44.         Future<Bundle> bundle = account.send(
  45.                 cda.getDepositAddress().getHashCheckSum(),
  46.                 cda.getRequest().getExpectedAmount(),
  47.                 Optional.of("Thanks for that pizza!"), Optional.of("OMNOMNOM"));
Add Comment
Please, Sign In to add comment