◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
安装web3go
1 |
git clone https://github.com/bcl-chain/web3.go.git |
1
2
3
4
|
// generate frameworkgomobile bind -target=ios./github.com/bcl-chain/web3.go/mobile// generate arr jargomobile bind -target=android./github.com/bcl-chain/web3.go/mobile |
安装依赖
1
2
3
|
yarn
react-native run-androidreact-native run-ios |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// IOS
RCT_EXPORT_METHOD(getBalance:(NSString*) address:(RCTPromiseResolveBlock)resolverejecter:(RCTPromiseRejectBlock)reject){// ip地址Web3goEthereumClient* client = Web3goNewEthereumClient(nodeIP, nil);
Web3goContext* ctx = Web3goNewContext();// 账户地址Web3goAddress* address1 = Web3goNewAddressFromHex(address, nil);
@try {
Web3goBigInt* a = [client getBalanceAt:ctx account:address1 number:-1 error:nil];
NSString* ammount = [a getString:10];NSLog(@%@, ammount);resolve(ammount);} @catch (NSError *exception) {NSLog(@NSError: %@, exception);reject(@NSError: %@, @There were no events, exception);} @finally {NSLog(@finally);}
}
// android@ReactMethodpublic void getBalance(String address, Promise promise) {try {
web3go.EthereumClient client = Web3go.newEthereumClient(nodeIP);
web3go.Context ctx = Web3go.newContext();web3go.Address address1 = Web3go.newAddressFromHex(address);web3go.BigInt a = client.getBalanceAt(ctx, address1, -1);String ammout = a.getString(10);promise.resolve(ammout); |
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。