Skip to content

Commit

Permalink
Merge pull request #11 from elven-js/migrate-v13
Browse files Browse the repository at this point in the history
migrate to sdk v13
  • Loading branch information
juliancwirko authored Apr 28, 2024
2 parents d5f15a2 + 7090846 commit c5d1873
Show file tree
Hide file tree
Showing 17 changed files with 1,001 additions and 821 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
meta.txt
meta.json
stats.html
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
### [0.18.0](https://github.com/elven-js/elven.js/releases/tag/v0.18.0) (2024-04-28)
- switch to SDK v13
- breaking: `SmartContract` is no longer exported, use `SmartContractTransactionsFactory`
- breaking: `GasEstimator` removed
- breaking: `ContractFunction` removed, pass normal strings
- breaking: `TransactionPayload` removed, you can now pass `Uint8Array` instead
- update examples
- update reexported functions and helpers
- return transaction on network in `onTxFinalized`
- added two amount related helper functions: `parseAmount` and `formatAmount`

### [0.17.0](https://github.com/elven-js/elven.js/releases/tag/v0.17.0) (2024-01-29)
- remove onLoginEnd and onLogoutEnd callbacks. With success and failure callbacks, they are not needed
- fix duplicate callbacks calls
Expand Down
92 changes: 51 additions & 41 deletions build/elven.js

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions build/types/elven.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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 { TokenTransfer, TokenComputer, Token, } from '@multiversx/sdk-core/out/tokens';
export { TokenOperationsFactory, TokenOperationsFactoryConfig, TokenOperationsOutcomeParser, } from '@multiversx/sdk-core/out/tokenOperations';
export { TransferTransactionsFactory, TransactionsFactoryConfig, SmartContractTransactionsFactory, TokenManagementTransactionsFactory, } from '@multiversx/sdk-core/out/transactionsFactories/';
export { SmartContractTransactionsOutcomeParser, TokenManagementTransactionsOutcomeParser, TransactionEventsParser, } from '@multiversx/sdk-core/out/transactionsOutcomeParsers';
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 { TransactionComputer } from '@multiversx/sdk-core/out/transactionComputer';
export { Message, MessageComputer } from '@multiversx/sdk-core/out/message';
export { TransactionWatcher } from '@multiversx/sdk-core/out/transactionWatcher';
export { SmartContract } from '@multiversx/sdk-core/out/smartcontracts/smartContract';
export { ContractFunction } from '@multiversx/sdk-core/out/smartcontracts/function';
export { SignableMessage } from '@multiversx/sdk-core/out/signableMessage';
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';
Expand All @@ -16,4 +16,5 @@ export { AddressType, AddressValue, } from '@multiversx/sdk-core/out/smartcontra
export { QueryArguments } from '@multiversx/sdk-core/out/smartcontracts/interface';
export { ContractQueryResponse } from '@multiversx/sdk-network-providers/out/contractQueryResponse';
export { ElvenJS } from './main';
export { parseAmount, formatAmount } from './utils/amount';
export * from './types';
21 changes: 21 additions & 0 deletions build/types/utils/amount.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type AmountArgs = {
amount: string;
decimals: number;
rounding?: number;
};
/**
* Parses the amount from string
* @param amount
* @param decimals
* @returns bigInt
*/
export declare const parseAmount: ({ amount, decimals, }: Omit<AmountArgs, 'rounding'>) => bigint;
/**
* Formats the amount from string (bigInt)
* @param amount
* @param decimals
* @param rounding
* @returns string
*/
export declare const formatAmount: ({ amount, decimals, rounding, }: AmountArgs) => string;
export {};
24 changes: 24 additions & 0 deletions esbuild.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const esbuild = require('esbuild');
const path = require('path');

const fs = require('fs');

Expand All @@ -13,6 +14,29 @@ esbuild
minify: true,
outdir: 'build',
platform: 'browser',
plugins: [
{
name: 'alias',
setup(build) {
build.onResolve({ filter: /^bignumber\.js$/ }, () => {
return {
path: path.resolve(
__dirname,
'node_modules/bignumber.js/bignumber.mjs'
),
};
});
build.onResolve({ filter: /^buffer$/ }, () => {
return {
path: path.resolve(
__dirname,
'node_modules/node-stdlib-browser/node_modules/buffer/index.js'
),
};
});
},
},
],
})
.then((result) => {
fs.writeFileSync('./build/meta.json', JSON.stringify(result.metafile));
Expand Down
92 changes: 51 additions & 41 deletions example/elven.js

Large diffs are not rendered by default.

57 changes: 32 additions & 25 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ <h3>Other demos:</h3>
ElvenJS,
Transaction,
Address,
TransactionPayload,
TokenTransfer,
Token,
TransferTransactionsFactory,
TransactionsFactoryConfig,
TokenComputer,
U32Value,
AddressValue,
SmartContract,
GasEstimator,
ContractFunction
SmartContractTransactionsFactory,
parseAmount,
} from './elven.js';

// Options are the defaults and here only to show all of them
Expand Down Expand Up @@ -295,13 +296,15 @@ <h3>Other demos:</h3>
// See more about gas limit calculation here: https://docs.multiversx.com/developers/gas-and-fees/overview/
const gasLimit = ((isGuardian || isXalias) ? 100000 : 50000) + 1500 * demoMessage.length;

const textEncoder = new TextEncoder();

const tx = new Transaction({
nonce: ElvenJS.storage.get('nonce'),
receiver: new Address(egldTransferAddress),
gasLimit,
chainID: 'D',
data: new TransactionPayload(demoMessage),
value: TokenTransfer.egldFromAmount(0.001),
data: textEncoder.encode(demoMessage),
value: parseAmount({ amount: '0.001', decimals: 18 }),
sender: new Address(ElvenJS.storage.get('address')),
});

Expand All @@ -320,19 +323,19 @@ <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-22c0a5 token: https://r3d4.fr/faucet
const transfer = TokenTransfer.fungibleFromAmount(
'BUILDO-22c0a5',
'1',
18
);
const tokenTransfer = new TokenTransfer({
token: new Token({ identifier: 'BUILDO-22c0a5' }),
amount: parseAmount({ amount: '1', decimals: 18 }),
});

const factory = new TransferTransactionsFactory(new GasEstimator());
const factory = new TransferTransactionsFactory({
config: new TransactionsFactoryConfig({ chainID: 'D' }),
});

const tx = factory.createESDTTransfer({
tokenTransfer: transfer,
const tx = factory.createTransactionForESDTTokenTransfer({
receiver: new Address(esdtTransferAddress),
sender: new Address(ElvenJS.storage.get('address')),
chainID: 'D',
tokenTransfers: [tokenTransfer]
});

try {
Expand All @@ -347,21 +350,25 @@ <h3>Other demos:</h3>
const nftMinterSmartContract = 'erd1qqqqqqqqqqqqqpgqufmyqvy3kvda2uywqgx809lglxftq9t667es3956pv';
document.getElementById('button-mint').addEventListener('click', async () => {
const contractAddress = new Address(nftMinterSmartContract);
const contract = new SmartContract({ address: contractAddress });

const isGuardian = ElvenJS.storage.get('activeGuardian');
// Additional 50000 when there is an active guardian
// See more about gas limit calculation here: https://docs.multiversx.com/developers/gas-and-fees/overview/
const gasLimit = isGuardian ? 14050000 : 14000000;

const tx = contract.call({
caller: new Address(ElvenJS.storage.get('address')),
value: TokenTransfer.egldFromAmount(0.01),
func: new ContractFunction("mint"),
gasLimit,
args: [new U32Value(1)],
chainID: "D"
})
const factory = new SmartContractTransactionsFactory({
config: new TransactionsFactoryConfig({ chainID: 'D' }),
});

const tx = factory.createTransactionForExecute({
sender: new Address(ElvenJS.storage.get('address')),
contract: new Address(contractAddress),
function: 'mint',
nativeTransferAmount: parseAmount({ amount: '0.01', decimals: 18 }),
gasLimit: BigInt(gasLimit),
arguments: [new U32Value(1)],
});

try {
await ElvenJS.signAndSendTransaction(tx);
} catch (e) {
Expand All @@ -379,7 +386,7 @@ <h3>Other demos:</h3>
try {
await ElvenJS.queryContract({
address: new Address(nftMinterSmartContract),
func: new ContractFunction('getMintedPerAddressTotal'),
func: 'getMintedPerAddressTotal',
args: [new AddressValue(new Address(ElvenJS.storage.get('address')))]
});
} catch (e) {
Expand Down
Loading

0 comments on commit c5d1873

Please sign in to comment.