Skip to content

Files

Latest commit

803fdb7 · Jun 2, 2018

History

History
116 lines (81 loc) · 3.14 KB

README.md

File metadata and controls

116 lines (81 loc) · 3.14 KB

Install

1. Git clone this repo.

2. Drag iosSDK.xcodeproj file to your project.

1

3. Add link library.

2

4. Add header search path by dragging iosSDK folder to the setting area.

3

Usage

Wallet

Import NASSmartContracts.h file.

#import <NASSmartContracts.h>

1. Debug mode

[NASSmartContracts debug:YES]; // use the debug net

2. Check wallet APP

if (![NASSmartContracts nasNanoInstalled]) {
    // if wallet APP is not installed, go to AppStore.
    [NASSmartContracts goToNasNanoAppStore];
}

3. Pay

    self.sn = [NASSmartContracts randomCodeWithLength:32];
    NSError *error = [NASSmartContracts payNas:@(0.0001)
                                     toAddress:@"n1a4MqSPPND7d1UoYk32jXqKb5m5s3AN6wB"
                              withSerialNumber:self.sn
                                  forGoodsName:@"test1"
                                       andDesc:@"desc"];

4. Call contract function

    self.sn = [NASSmartContracts randomCodeWithLength:32];
    NSError *error = [NASSmartContracts callWithMethod:@"save"
                                               andArgs:@[@"key111", @"value111"]
                                                payNas:@(0)
                                             toAddress:@"n1zVUmH3BBebksT4LD5gMiWgNU9q3AMj3se"
                                      withSerialNumber:self.sn
                                          forGoodsName:@"test2"
                                               andDesc:@"desc2"];

5. Check status

    [NASSmartContracts checkStatusWithSerialNumber:self.sn
                             withCompletionHandler:^(NSDictionary *data) {
                                 NSData *json = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
                                 NSString *string = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
                                 NSLog(@"%@", string);
                             } errorHandler:^(NSInteger code, NSString *msg) {
                                 NSLog(@"%@", msg);
                             }];

API

Import NASApi.h file.

#import <NASApi.h>

1. Debug mode

Debug mode will connect to the debug net.

[NASApi debug:YES]; // use the debug net

2. call API

See the API document.

We do not define model for response and return a dictionary instead. You can use your favorite json library to parse the data.

completionHandler:(void (^)(NSDictionary *data))handler
errorHandler:(void (^)(NSString *msg))errorHandler

3. Contract

You can form a contract by calling contractWithSource:andSourceType:andFunction:andArgs.

    [NASApi contractWithSource:nil
                 andSourceType:nil
                   andFunction:@"transferValue"
                       andArgs:[@(500)]];