Skip to content

Commit

Permalink
Merge pull request #7 from juliancwirko/sdk-core-migration
Browse files Browse the repository at this point in the history
migrate to newest sdk-core
  • Loading branch information
juliancwirko authored Apr 10, 2023
2 parents b9eeb8c + a99c800 commit b067c32
Show file tree
Hide file tree
Showing 16 changed files with 868 additions and 718 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### [0.9.0](https://github.com/juliancwirko/elven.js/releases/tag/v0.9.0) (2023-04-10)
- migrate to MultiversX JS SDK 12.1.0 **(breaking changes):**
- `TokenPayment` is now `TokenTransfer`
- `ESDTNFTTransferPayloadBuilder` and `ESDTTransferPayloadBuilder` are deprecated and removed, instead please use `TransferTransactionsFactory`
- `ContractCallPayloadBuilder` is removed, please use `SmartContract.call` instead
- See all changes in the [example](example/index.html), also please check [MultiversX SDK JS Cookbook](https://docs.multiversx.com/sdk-and-tools/sdk-js/sdk-js-cookbook/#signing-objects) for how to build payload structures
- update dependecies

### [0.8.2](https://github.com/juliancwirko/elven.js/releases/tag/v0.8.2) (2023-03-05)
- fix browser extension signing states

Expand Down
42 changes: 26 additions & 16 deletions build/elven.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions build/types/elven.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
export { TokenPayment } from '@multiversx/sdk-core/out/tokenPayment';
export { ESDTNFTTransferPayloadBuilder, ESDTTransferPayloadBuilder, } from '@multiversx/sdk-core/out/tokenTransferBuilders';
export { TokenTransfer } from '@multiversx/sdk-core/out/tokenTransfer';
export { TransferTransactionsFactory } from '@multiversx/sdk-core/out/transferTransactionsFactory';
export { GasEstimator } from '@multiversx/sdk-core/out/gasEstimator';
export { Address } from '@multiversx/sdk-core/out/address';
export { Account } from '@multiversx/sdk-core/out/account';
export { Transaction } from '@multiversx/sdk-core/out/transaction';
export { TransactionPayload } from '@multiversx/sdk-core/out/transactionPayload';
export { TransactionWatcher } from '@multiversx/sdk-core/out/transactionWatcher';
export { BytesValue } from '@multiversx/sdk-core/out/smartcontracts/typesystem/bytes';
export { BigUIntValue, U32Value, } from '@multiversx/sdk-core/out/smartcontracts/typesystem/numerical';
export { BooleanValue } from '@multiversx/sdk-core/out/smartcontracts/typesystem/boolean';
export { ContractCallPayloadBuilder } from '@multiversx/sdk-core/out/smartcontracts/transactionPayloadBuilders';
export { SmartContract } from '@multiversx/sdk-core/out/smartcontracts/smartContract';
export { ContractFunction } from '@multiversx/sdk-core/out/smartcontracts/function';
export { AddressValue } from '@multiversx/sdk-core/out/smartcontracts/typesystem/address';
export { BytesType, BytesValue, } from '@multiversx/sdk-core/out/smartcontracts/typesystem/bytes';
export { U16Type, U16Value, U32Type, U32Value, U64Type, U64Value, U8Type, U8Value, BigUIntType, BigUIntValue, } from '@multiversx/sdk-core/out/smartcontracts/typesystem/numerical';
export { BooleanType, BooleanValue, } from '@multiversx/sdk-core/out/smartcontracts/typesystem/boolean';
export { AddressType, AddressValue, } from '@multiversx/sdk-core/out/smartcontracts/typesystem/address';
export { ElvenJS } from './main';
export { LoginMethodsEnum } from './types';
2 changes: 1 addition & 1 deletion build/types/network-provider.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="node" />
import BigNumber from 'bn.js';
import BigNumber from 'bignumber.js';
import { Address } from '@multiversx/sdk-core/out/address';
import { TransactionStatus } from '@multiversx/sdk-network-providers/out/transactionStatus';
import { TransactionReceipt } from '@multiversx/sdk-network-providers/out/transactionReceipt';
Expand Down
2 changes: 1 addition & 1 deletion build/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface LoginOptions {
callbackRoute?: string;
}
export declare enum DappCoreWCV2CustomMethodsEnum {
erd_cancelAction = "erd_cancelAction"
mvx_cancelAction = "mvx_cancelAction"
}
export declare enum EventStoreEvents {
onLoginPending = "onLoginPending",
Expand Down
6 changes: 0 additions & 6 deletions esbuild.config.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const esbuild = require('esbuild');

// Bring back if needed
// const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
// const stdLibBrowser = require('node-stdlib-browser');

const fs = require('fs');

esbuild
Expand All @@ -17,8 +13,6 @@ esbuild
'process.env.NODE_ENV': 'production',
},
format: 'esm',
// Bring back if needed
// plugins: [plugin(stdLibBrowser)],
entryPoints: ['./src/elven.ts'],
bundle: true,
metafile: true,
Expand Down
42 changes: 26 additions & 16 deletions example/elven.js

Large diffs are not rendered by default.

53 changes: 30 additions & 23 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ <h3>Other demos:</h3>
Transaction,
Address,
TransactionPayload,
TokenPayment,
ContractCallPayloadBuilder,
ContractFunction,
TokenTransfer,
TransferTransactionsFactory,
U32Value,
ESDTTransferPayloadBuilder,
AddressValue,
SmartContract,
GasEstimator,
ContractFunction
} from './elven.js';

// Options are the defaults and here only to show all of them
Expand Down Expand Up @@ -249,7 +250,7 @@ <h3>Other demos:</h3>
gasLimit: 50000 + 1500 * demoMessage.length,
chainID: 'D',
data: new TransactionPayload(demoMessage),
value: TokenPayment.egldFromAmount(0.001),
value: TokenTransfer.egldFromAmount(0.001),
sender: new Address(ElvenJS.storage.get('address')),
});

Expand All @@ -270,16 +271,16 @@ <h3>Other demos:</h3>
// You need to know its ticker and how many decimals places it has
// In this case, the token has 18 decimal places. You can check it in the MultiversX devnet explorer
// You can use the community-based faucet to get the BUILDO-890d14 token: https://r3d4.fr/faucet
const payment = TokenPayment.fungibleFromAmount(
const transfer = TokenTransfer.fungibleFromAmount(
'BUILDO-890d14',
'1',
18
);
const data = new ESDTTransferPayloadBuilder().setPayment(payment).build();

const tx = new Transaction({
data,
gasLimit: 50000 + 1500 * data.length() + 300000,
const factory = new TransferTransactionsFactory(new GasEstimator());

const tx = factory.createESDTTransfer({
tokenTransfer: transfer,
receiver: new Address(esdtTransferAddress),
sender: new Address(ElvenJS.storage.get('address')),
chainID: 'D',
Expand All @@ -296,21 +297,20 @@ <h3>Other demos:</h3>
// It mints on the smart contract from: https://dapp-demo.elven.tools/
const nftMinterSmartContract = 'erd1qqqqqqqqqqqqqpgqztp5vpqrxe2tha224jwsa3sv2800a88zgtksar2kc8';
document.getElementById('button-mint').addEventListener('click', async () => {

updateTxHashContainer(false);
const data = new ContractCallPayloadBuilder()
.setFunction(new ContractFunction('mint'))
.setArgs([new U32Value(1)])
.build();

const tx = new Transaction({
data,
gasLimit: 14000000,
value: TokenPayment.egldFromAmount(0.01),
chainID: 'D',
receiver: new Address(nftMinterSmartContract),
sender: new Address(ElvenJS.storage.get('address')),
});
const contractAddress = new Address(nftMinterSmartContract);
const contract = new SmartContract({ address: contractAddress });

const tx = contract.call({
caller: new Address(ElvenJS.storage.get('address')),
value: TokenTransfer.egldFromAmount(0.01),
func: new ContractFunction("mint"),
gasLimit: 14000000,
args: [new U32Value(1)],
chainID: "D"
})
try {
await ElvenJS.signAndSendTransaction(tx);
} catch (e) {
Expand All @@ -328,6 +328,7 @@ <h3>Other demos:</h3>
try {
updateQueryResultContainer();
uiPending(true);

const results = await ElvenJS.queryContract({
address: new Address(nftMinterSmartContract),
func: new ContractFunction('getMintedPerAddressTotal'),
Expand All @@ -337,8 +338,14 @@ <h3>Other demos:</h3>
uiPending(false);

// Manual decoding of a simple type (number here), there will be additional tools for that
// For more possibilities, for now please check data converter in Buildo CLI:
// https://github.com/xdevguild/buildo-begins/blob/main/src/converters.ts
const hexVal = base64ToDecimalHex(results?.returnData?.[0]);
updateQueryResultContainer(`➡️ The result of the query is: ${parseInt(hexVal, 16)}`);
let intVal = 0;
if (hexVal) {
intVal = parseInt(hexVal, 16);
}
updateQueryResultContainer(`➡️ The result of the query is: ${intVal}`);
} catch (e) {
uiPending(false);
throw new Error(e?.message);
Expand Down
Loading

0 comments on commit b067c32

Please sign in to comment.