sdk-js-core 10 brought a series of breaking changes. Most importantly, the packages walletcore, dapp, contractWrappers and the network providers (ApiProvider
, ProxyProvider
) have been extracted to separate repositories - consequently, they are now distributed as separate NPM packages. sdk-core does not depend anymore on the libraries fs, crypto and axios.
The classes responsible with parsing contract results or query responses, and the ones responsible with transaction completion detection have been rewritten, as well.
Furthermore, we have removed a couple of previously-thought as utility functions, in order to simplify and improve the codebase of sdk-core.
Balance vs. TokenPayment
In sdk-core 10, the classes Balance
and BalanceBuilder
do not exist anymore.
Instead, a TokenPayment
or an IAccountBalance
(a simple BigNumber
) should be used instead, depending on the case.
sdk-core 9x:
let balance = Balance.egld(1);
sdk-core 10:
let paymentEGLD = TokenPayment.egldFromAmount("1");
let paymentFungible = TokenPayment.fungibleFromBigInteger(identifier, "1000000", numDecimals);
let paymentNonFungible = TokenPayment.nonFungible(identifier, nonce);
Transaction broadcasting and fetching
The following utility functions are not available anymore: transaction.send()
, transaction.getAsOnNetwork()
.
Instead, one should directly call a network provider:
await networkProvider.sendTransaction(tx);
await networkProvider.getTransaction(txHash)
Transaction awaiting
In sdk-core 10, the following utility functions are not available anymore: transaction.awaitExecuted()
, transaction.awaitPending()
.
Instead, one should directly use the TransactionWatcher
:
let transactionWatcher = new TransactionWatcher(networkProvider);
await watcher.awaitCompleted(tx);
Fetching network configuration
In sdk-core 10, we have removed the utility functions NetworkConfig.getDefault()
and NetworkConfig.sync()
.
Instead, one should fetch the network configuration as follows:
let networkConfig = await provider.getNetworkConfig();
Then cache the response, if needed.
Nonce, gas limit, gas price, chain ID
In sdk-core 10, the classes Nonce
, GasLimit
, GasPrice
and ChainID
do not exist anymore.
Instead, one should simply use primitives when creating transactions / interactions:
let tx = new Transaction({
nonce: 7,
data: new TransactionPayload("helloWorld"),
gasLimit: 70000,
gasPrice: 1000000000,
receiver: new Address("erd1..."),
value: TokenPayment.egldFromAmount(1),
chainID: "D"
});
Creating contract queries
The function smartContract.runQuery()
has been removed, in order to decouple the SmartContract
class from the network provider.
In sdk-core 10, one should do as follows:
let query = smartContract.createQuery({ /* ... */ });
let queryResponse = await networkProvider.queryContract(query);
smartContract.createQuery()
+ provider.queryContract()
have to be used, instead.
Creating interactions using "contract.methods"
In erdsdk-corejs 10, when using contract.methods.myContractFunction([a, b, c])
, the type inference system comes into play.
That is, you cannot write the following anymore:
let interaction = <Interaction>this.contract.methods.getLotteryInfo([
BytesValue.fromUTF8("my-lottery")
]);
Instead, you have to either not provide typed values ar arguments (automatic type inference will be applied):
let interaction = <Interaction>this.contract.methods.getLotteryInfo(["my-lottery")]);
- or to provide typed values, as before, but using the methodsExplicit
object:
let interaction = <Interaction>this.contract.methodsExplicit.getLotteryInfo([
BytesValue.fromUTF8("my-lottery")
]);
Parsing contract results
The modules designed to parse the contract results have been rewritten in sdk-core 10. ExecutionResultsBundle
and QueryResponseBundle
have been removed, and replaced by TypedOutcomeBundle
(and its untyped counterpart, UntypedOutcomeBundle
). SmartContractResults
has been changed to not use the concepts immediate result
and resulting calls
anymore. Instead, interpreting SmartContractResults.items
is now the responsibility of the ResultsParser
. interpretQueryResponse()
and interpretExecutionResults()
do not exist on the Interaction
object anymore. DefaultInteractionRunner
has been removed, as well.
The functions getReceipt()
, getSmartContractResults()
and getLogs()
of TransactionOnNetwork
have been removed. The underlying properties are now public. Furthermore, TransactionOnNetwork
is now defined within @multiversx/sdk-network-providers
.
In order to parse contract results in sdk-core 10, please follow this guide.
EsdtHelpers
and ScArgumentsParser
vs. transaction-decoder
In sdk-core 10, the classes EsdtHelpers
and ScArgumentsParser
have been removed.
Instead, one should reference and use the package @multiversx/sdk-transaction-decoder.
ChainID is now required
ChainID
is now a required parameter of the Transaction
constructor.
Furthermore, interaction.withChainID("D")
must be used before calling interaction.buildTransaction()
.
let tx = interaction
.withNonce(7)
.withGasLimit(20000000)
.withChainID("D")
.buildTransaction();