@@ -20,37 +20,45 @@ Get a valid [`NetworkConfig`](https://github.com/RemarkableTools/Mx.NET.SDK/blob
2020``` csharp
2121var networkConfig = await NetworkConfig .GetFromNetwork (provider );
2222```
23- Create a [ ` Signer ` ] ( https://github.com/RemarkableTools/Mx.NET.SDK/blob/master/src/Mx.NET.SDK.Wallet/Wallet/Signer .cs ) instance by providing the key file and the associated password
23+ Create a [ ` Signer ` ] ( https://github.com/RemarkableTools/Mx.NET.SDK/blob/master/src/Mx.NET.SDK.Wallet/Wallet/WalletSigner .cs ) instance by providing the key file and the associated password
2424``` csharp
2525var filePath = " PATH/TO/KEYFILE.json" ;
2626var password = " PASSWORD" ;
27- var signer = Signer .FromKeyFile (filePath , password );
27+ var signer = WalletSigner .FromKeyFile (filePath , password );
2828```
2929Set up my Account and Receiver Address
3030``` csharp
31- var myAccount = Account .From (await provider .GetAccount (signer .GetAddress ().Bech32 ));
31+ var account = Account .From (await provider .GetAccount (signer .GetAddress ().Bech32 ));
3232var receiverAddress = Address .FromBech32 (" RECEIVER_ADDRESS" );
3333```
3434Get a token from network
3535``` csharp
36- var token = Token .From (await provider .GetToken (" OFE-29eb54 " ));
36+ var token = Token .From (await provider .GetToken (" BUSD-632f7d " ));
3737```
3838Create the [ ` Transaction Request ` ] ( https://github.com/RemarkableTools/Mx.NET.SDK/blob/master/src/Mx.NET.SDK/Domain/TransactionRequest.cs )
3939``` csharp
4040var transactionRequest = TokenTransactionRequest .TokenTransfer (
4141 networkConfig ,
4242 account ,
4343 receiverAddress ,
44- token .Identifier . Value ,
45- ESDTAmount .ESDT (" 100" , token .GetESDT ()). Value );
44+ token .Identifier ,
45+ ESDTAmount .ESDT (" 100" , token .GetESDT ()));
4646```
4747Use the [ ` Wallet Methods ` ] ( https://github.com/RemarkableTools/Mx.NET.SDK/blob/master/src/Mx.NET.SDK.Wallet/WalletMethods.cs ) to sign the transaction
4848``` csharp
49- var signedTransaction = transactionRequest . Sign ( signer );
49+ var signedTransaction = signer . SignTransaction ( transactionRequest );
5050```
5151POST the transaction to MultiversX API
5252``` csharp
53- var response = await provider .SendTransaction (signedTransaction );
53+ try
54+ {
55+ var response = await provider .SendTransaction (signedTransaction );
56+ // other instructions
57+ }
58+ catch (Exception ex )
59+ {
60+ Console .WriteLine (ex .Message );
61+ }
5462```
5563Get the [ ` Transaction ` ] ( https://github.com/RemarkableTools/Mx.NET.SDK/blob/master/src/Mx.NET.SDK/Domain/Data/Transaction/Transaction.cs ) from response and await for execution to finalize
5664``` csharp
@@ -65,25 +73,58 @@ Console.WriteLine($"Transaction executed with status {transaction.Status}");
6573The example is created for the [ adder] ( https://github.com/multiversx/mx-sdk-rs/tree/master/contracts/examples/adder ) contract.
6674#### Create a [ ` EGLD Transaction Request ` ] ( https://github.com/RemarkableTools/Mx.NET.SDK/blob/master/src/Mx.NET.SDK/TransactionsManager/EGLDTransactionRequest.cs ) to a Smart Contract, sign it and send it to the network
6775``` csharp
68- var transactionRequest = EGLDTransactionRequest .EGLDTransferToSmartContract (
69- networkConfig ,
70- account ,
71- smartContractAddress ,
72- ESDTAmount .Zero (),
73- " add" ,
74- NumericValue .BigUintValue (10 ));
75- var signedTransaction = transactionRequest .Sign (signer );
76- var response = await provider .SendTransaction (signedTransaction );
77- var transaction = Transaction .From (response .TxHash );
78- await transaction .AwaitExecuted (provider );
79- Console .WriteLine ($" Transaction executed with status {transaction .Status }" );
76+ try
77+ {
78+ var transactionRequest = EGLDTransactionRequest .EGLDTransferToSmartContract (
79+ networkConfig ,
80+ account ,
81+ smartContractAddress ,
82+ ESDTAmount .Zero (),
83+ " add" ,
84+ NumericValue .BigUintValue (10 ));
85+ var signedTransaction = signer .SignTransaction (transactionRequest );
86+ var response = await provider .SendTransaction (signedTransaction );
87+ var transaction = Transaction .From (response .TxHash );
88+ await transaction .AwaitExecuted (provider );
89+ Console .WriteLine ($" Transaction executed with status {transaction .Status }" );
90+ }
91+ catch (Exception ex )
92+ {
93+ Console .WriteLine (ex .Message );
94+ }
8095```
8196#### Query smart contract
8297``` csharp
98+ var smartContractAddress = Address .FromBech32 (" CONTRACT_BECH32_ADDRESS" );
8399var outputType = TypeValue .BigUintTypeValue ;
84100var queryResult = await SmartContract .QuerySmartContract <NumericValue >(provider ,
85101 smartContractAddress ,
86102 outputType ,
87103 " getSum" );
88104Console .WriteLine (queryResult .Number );
105+
106+ // query array from Smart Contract (random example)
107+ var queryArrayResult = await SmartContract .QueryArraySmartContract <Address >(provider ,
108+ smartContractAddress ,
109+ TypeValue .AddressValue ,
110+ " getUsers" );
111+ foreach (var user in queryArrayResult )
112+ Console .WriteLine (user .Bech32 );
113+
114+ // more complex reading from Smart Contract storage (random example)
115+ uint day = 1 ;
116+ var dayRewards = await SmartContract .QueryArraySmartContract <StructValue >(provider ,
117+ smartContractAddress ,
118+ TypeValue .StructValue (" EsdtTokenPayment" , new FieldDefinition [3 ]
119+ {
120+ new FieldDefinition (" token_identifier" , " " , TypeValue .TokenIdentifierValue ),
121+ new FieldDefinition (" token_nonce" , " " , TypeValue .U64TypeValue ),
122+ new FieldDefinition (" amount" , " " , TypeValue .BigUintTypeValue )
123+ }),
124+ " getDayRewards" ,
125+ null ,
126+ NumericValue .U32Value (day ));
127+ foreach (var esdt in dayRewards )
128+ Console .WriteLine ($" {esdt .Fields [0 ].Value } {esdt .Fields [1 ].Value } {esdt .Fields [2 ].Value }" );
129+ // You can map the StructValue from response to you custom class object for easier usage, if you need
89130```
0 commit comments