Skip to content

Commit 76847b0

Browse files
authored
Merge pull request #658 from multiversx/main
Merge main in feat next
2 parents e4eb233 + a8b357a commit 76847b0

File tree

8 files changed

+89
-58
lines changed

8 files changed

+89
-58
lines changed

cookbook/cookbook.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,18 +2402,16 @@ After the `10-epoch unbonding period` is complete, we can proceed with withdrawi
24022402
```
24032403

24042404
### Relayed transactions
2405-
We are currently on the `third iteration (V3)` of relayed transactions. V1 and V2 will soon be deactivated, so we will focus on V3.
2405+
We are currently on the third iteration (V3) of relayed transactions. V1 and V2 will be deactivated soon, so we'll focus on V3.
24062406

2407-
For V3, two new fields have been added to transactions:
2408-
- relayer
2409-
- relayerSignature
2407+
For V3, two new fields have been added on transactions: `relayer` and `relayerSignature`.
24102408

2411-
Signing Process:
2412-
1. The relayer must be set before the sender signs the transaction.
2413-
2. Once the sender has signed, the relayer can also sign the transaction and broadcast it.
2409+
Note that:
2410+
1. the sender and the relayer can sign the transaction in any order.
2411+
2. before any of the sender or relayer can sign the transaction, the `relayer` field must be set.
2412+
3. relayed transactions require an additional `50,000` of gas.
2413+
4. the sender and the relayer must be in the same network shard.
24142414

2415-
**Important Consideration**:
2416-
Relayed V3 transactions require an additional `50,000` gas.
24172415
Let’s see how to create a relayed transaction:
24182416

24192417
```js

cookbook/relayed.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ import { Account, Address, DevnetEntrypoint, Transaction } from "../src"; // md-
33
// md-start
44
(async () => {
55
// ### Relayed transactions
6-
// We are currently on the `third iteration (V3)` of relayed transactions. V1 and V2 will soon be deactivated, so we will focus on V3.
7-
8-
// For V3, two new fields have been added to transactions:
9-
// - relayer
10-
// - relayerSignature
11-
12-
// Signing Process:
13-
// 1. The relayer must be set before the sender signs the transaction.
14-
// 2. Once the sender has signed, the relayer can also sign the transaction and broadcast it.
15-
16-
// **Important Consideration**:
17-
// Relayed V3 transactions require an additional `50,000` gas.
6+
// We are currently on the third iteration (V3) of relayed transactions. V1 and V2 will be deactivated soon, so we'll focus on V3.
7+
//
8+
// For V3, two new fields have been added on transactions: `relayer` and `relayerSignature`.
9+
//
10+
// Note that:
11+
// 1. the sender and the relayer can sign the transaction in any order.
12+
// 2. before any of the sender or relayer can sign the transaction, the `relayer` field must be set.
13+
// 3. relayed transactions require an additional `50,000` of gas.
14+
// 4. the sender and the relayer must be in the same network shard.
15+
//
1816
// Let’s see how to create a relayed transaction:
1917

2018
// ```js

package-lock.json

Lines changed: 42 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@multiversx/sdk-core",
3-
"version": "15.0.0-beta.0",
3+
"version": "15.1.1",
44
"description": "MultiversX SDK for JavaScript and TypeScript",
55
"author": "MultiversX",
66
"homepage": "https://multiversx.com",

src/core/errors.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ export class ExpectedAccountConditionNotReachedError extends Err {
445445
*/
446446
export class ErrGasLimitCannotBeEstimated extends Err {
447447
public constructor(error: Error) {
448-
super(`Failed to estimate gas limit: ${error}`, error);
448+
super(`Failed to estimate gas limit: [${error}]`, error);
449+
}
450+
}
451+
452+
export class ErrEstimateTransactionCost extends Err {
453+
public constructor(message: string) {
454+
super(message);
449455
}
450456
}

src/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from "./message";
1212
export * from "./networkParams";
1313
export * from "./smartContractQuery";
1414
export * from "./tokens";
15+
export * from "./tokenTransfersDataBuilder";
1516
export * from "./transaction";
1617
export * from "./transactionComputer";
1718
export * from "./transactionEvents";
@@ -20,4 +21,5 @@ export * from "./transactionOnNetwork";
2021
export * from "./transactionsFactoryConfig";
2122
export * from "./transactionStatus";
2223
export * from "./transactionWatcher";
24+
export * from "./utils.codec";
2325
export * from "./utils";

src/entrypoints/entrypoints.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { GasLimitEstimator } from "../gasEstimator";
1616
import { GovernanceController, GovernanceTransactionsFactory } from "../governance";
1717
import { MultisigTransactionsFactory } from "../multisig";
1818
import { MultisigController } from "../multisig/multisigController";
19-
import { ApiNetworkProvider, ProxyNetworkProvider } from "../networkProviders";
19+
import { ApiNetworkProvider, NetworkProviderConfig, ProxyNetworkProvider } from "../networkProviders";
2020
import { INetworkProvider } from "../networkProviders/interface";
2121
import { SmartContractTransactionsFactory } from "../smartContracts";
2222
import { SmartContractController } from "../smartContracts/smartContractController";
@@ -34,19 +34,21 @@ export class NetworkEntrypoint {
3434
constructor(options: {
3535
networkProviderUrl: string;
3636
networkProviderKind: string;
37+
networkProviderConfig?: NetworkProviderConfig;
3738
chainId: string;
3839
clientName?: string;
3940
withGasLimitEstimator?: boolean;
4041
gasLimitMultiplier?: number;
4142
}) {
43+
const networkProviderConfig: NetworkProviderConfig = {
44+
...(options.networkProviderConfig ?? {}),
45+
...(options.clientName && { clientName: options.clientName }),
46+
};
47+
4248
if (options.networkProviderKind === "proxy") {
43-
this.networkProvider = new ProxyNetworkProvider(options.networkProviderUrl, {
44-
clientName: options.clientName,
45-
});
49+
this.networkProvider = new ProxyNetworkProvider(options.networkProviderUrl, networkProviderConfig);
4650
} else if (options.networkProviderKind === "api") {
47-
this.networkProvider = new ApiNetworkProvider(options.networkProviderUrl, {
48-
clientName: options.clientName,
49-
});
51+
this.networkProvider = new ApiNetworkProvider(options.networkProviderUrl, networkProviderConfig);
5052
} else {
5153
throw new ErrInvalidNetworkProviderKind();
5254
}
@@ -267,12 +269,14 @@ export class TestnetEntrypoint extends NetworkEntrypoint {
267269
clientName?: string;
268270
withGasLimitEstimator?: boolean;
269271
gasLimitMultiplier?: number;
272+
networkProviderConfig?: NetworkProviderConfig;
270273
}) {
271274
const entrypointConfig = new TestnetEntrypointConfig();
272275
options = options || {};
273276
super({
274277
networkProviderUrl: options.url || entrypointConfig.networkProviderUrl,
275278
networkProviderKind: options.kind || entrypointConfig.networkProviderKind,
279+
networkProviderConfig: options.networkProviderConfig,
276280
chainId: entrypointConfig.chainId,
277281
clientName: options.clientName,
278282
withGasLimitEstimator: options.withGasLimitEstimator,
@@ -288,12 +292,14 @@ export class DevnetEntrypoint extends NetworkEntrypoint {
288292
clientName?: string;
289293
withGasLimitEstimator?: boolean;
290294
gasLimitMultiplier?: number;
295+
networkProviderConfig?: NetworkProviderConfig;
291296
}) {
292297
const entrypointConfig = new DevnetEntrypointConfig();
293298
options = options || {};
294299
super({
295300
networkProviderUrl: options.url || entrypointConfig.networkProviderUrl,
296301
networkProviderKind: options.kind || entrypointConfig.networkProviderKind,
302+
networkProviderConfig: options.networkProviderConfig,
297303
chainId: entrypointConfig.chainId,
298304
clientName: options.clientName,
299305
withGasLimitEstimator: options.withGasLimitEstimator,
@@ -309,12 +315,14 @@ export class MainnetEntrypoint extends NetworkEntrypoint {
309315
clientName?: string;
310316
withGasLimitEstimator?: boolean;
311317
gasLimitMultiplier?: number;
318+
networkProviderConfig?: NetworkProviderConfig;
312319
}) {
313320
const entrypointConfig = new MainnetEntrypointConfig();
314321
options = options || {};
315322
super({
316323
networkProviderUrl: options.url || entrypointConfig.networkProviderUrl,
317324
networkProviderKind: options.kind || entrypointConfig.networkProviderKind,
325+
networkProviderConfig: options.networkProviderConfig,
318326
chainId: entrypointConfig.chainId,
319327
clientName: options.clientName,
320328
withGasLimitEstimator: options.withGasLimitEstimator,

src/networkProviders/proxyNetworkProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Address,
33
ErrContractQuery,
4+
ErrEstimateTransactionCost,
45
ErrNetworkProvider,
56
getAxios,
67
prepareTransactionForBroadcasting,
@@ -148,6 +149,10 @@ export class ProxyNetworkProvider implements INetworkProvider {
148149

149150
const transaction = prepareTransactionForBroadcasting(copiedTx);
150151
const response = await this.doPostGeneric("transaction/cost", transaction);
152+
const returnMessage: string = response.returnMessage;
153+
if (returnMessage) {
154+
throw new ErrEstimateTransactionCost(returnMessage);
155+
}
151156
return TransactionCostResponse.fromHttpResponse(response);
152157
}
153158

0 commit comments

Comments
 (0)