Import NASSmartContracts.h file.
#import <NASSmartContracts.h>
[NASSmartContracts debug:YES]; // use the debug net
if (![NASSmartContracts nasNanoInstalled]) {
// if wallet APP is not installed, go to AppStore.
[NASSmartContracts goToNasNanoAppStore];
}
self.sn = [NASSmartContracts randomCodeWithLength:32];
NSError *error = [NASSmartContracts payNas:@(0.0001)
toAddress:@"n1a4MqSPPND7d1UoYk32jXqKb5m5s3AN6wB"
withSerialNumber:self.sn
forGoodsName:@"test1"
andDesc:@"desc"];
self.sn = [NASSmartContracts randomCodeWithLength:32];
NSError *error = [NASSmartContracts callWithMethod:@"save"
andArgs:@[@"key111", @"value111"]
payNas:@(0)
toAddress:@"n1zVUmH3BBebksT4LD5gMiWgNU9q3AMj3se"
withSerialNumber:self.sn
forGoodsName:@"test2"
andDesc:@"desc2"];
[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);
}];
Import NASApi.h file.
#import <NASApi.h>
Debug mode will connect to the debug net.
[NASApi debug:YES]; // use the debug net
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
You can form a contract by calling contractWithSource:andSourceType:andFunction:andArgs
.
[NASApi contractWithSource:nil
andSourceType:nil
andFunction:@"transferValue"
andArgs:[@(500)]];