genlayer-js 0.16.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/{index-DVMV4wM0.d.ts → index-BIyk5Fv7.d.ts} +12 -0
- package/dist/{index-DQUXmYng.d.cts → index-DrEvzYFA.d.cts} +12 -0
- package/dist/index.cjs +50 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -2
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/client/client.ts +2 -2
- package/src/contracts/actions.ts +44 -0
- package/src/types/clients.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 0.17.1 (2025-09-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* returning the whole data when an error occurs ([#111](https://github.com/genlayerlabs/genlayer-js/issues/111)) ([bebb025](https://github.com/genlayerlabs/genlayer-js/commit/bebb025a0f07d4ed05783e1a77abe76979fc4ac0))
|
|
9
|
+
|
|
10
|
+
## 0.17.0 (2025-09-03)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* allow gen_call write through `simulateWriteContract` ([#112](https://github.com/genlayerlabs/genlayer-js/issues/112)) ([734c0e6](https://github.com/genlayerlabs/genlayer-js/commit/734c0e61d9ddd13678f424ca6bd754ad1f4df3bb))
|
|
16
|
+
|
|
3
17
|
## 0.16.0 (2025-09-03)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -346,6 +346,18 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
346
346
|
leaderOnly?: boolean;
|
|
347
347
|
consensusMaxRotations?: number;
|
|
348
348
|
}) => Promise<any>;
|
|
349
|
+
simulateWriteContract: <RawReturn extends boolean | undefined>(args: {
|
|
350
|
+
account?: Account;
|
|
351
|
+
address: Address;
|
|
352
|
+
functionName: string;
|
|
353
|
+
args?: CalldataEncodable[];
|
|
354
|
+
kwargs?: Map<string, CalldataEncodable> | {
|
|
355
|
+
[key: string]: CalldataEncodable;
|
|
356
|
+
};
|
|
357
|
+
rawReturn?: RawReturn;
|
|
358
|
+
leaderOnly?: boolean;
|
|
359
|
+
transactionHashVariant?: TransactionHashVariant;
|
|
360
|
+
}) => Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable>;
|
|
349
361
|
deployContract: (args: {
|
|
350
362
|
account?: Account;
|
|
351
363
|
code: string | Uint8Array;
|
|
@@ -346,6 +346,18 @@ type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<Client<Transpor
|
|
|
346
346
|
leaderOnly?: boolean;
|
|
347
347
|
consensusMaxRotations?: number;
|
|
348
348
|
}) => Promise<any>;
|
|
349
|
+
simulateWriteContract: <RawReturn extends boolean | undefined>(args: {
|
|
350
|
+
account?: Account;
|
|
351
|
+
address: Address;
|
|
352
|
+
functionName: string;
|
|
353
|
+
args?: CalldataEncodable[];
|
|
354
|
+
kwargs?: Map<string, CalldataEncodable> | {
|
|
355
|
+
[key: string]: CalldataEncodable;
|
|
356
|
+
};
|
|
357
|
+
rawReturn?: RawReturn;
|
|
358
|
+
leaderOnly?: boolean;
|
|
359
|
+
transactionHashVariant?: TransactionHashVariant;
|
|
360
|
+
}) => Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable>;
|
|
349
361
|
deployContract: (args: {
|
|
350
362
|
account?: Account;
|
|
351
363
|
code: string | Uint8Array;
|
package/dist/index.cjs
CHANGED
|
@@ -523,6 +523,37 @@ var contractActions = (client, publicClient) => {
|
|
|
523
523
|
const resultBinary = _viem.fromHex.call(void 0, prefixedResult, "bytes");
|
|
524
524
|
return decode(resultBinary);
|
|
525
525
|
},
|
|
526
|
+
simulateWriteContract: async (args) => {
|
|
527
|
+
const {
|
|
528
|
+
account,
|
|
529
|
+
address,
|
|
530
|
+
functionName,
|
|
531
|
+
args: callArgs,
|
|
532
|
+
kwargs,
|
|
533
|
+
leaderOnly = false,
|
|
534
|
+
transactionHashVariant = "latest-nonfinal" /* LATEST_NONFINAL */
|
|
535
|
+
} = args;
|
|
536
|
+
const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
537
|
+
const serializedData = serialize(encodedData);
|
|
538
|
+
const senderAddress = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _8 => _8.address]), () => ( _optionalChain([client, 'access', _9 => _9.account, 'optionalAccess', _10 => _10.address])));
|
|
539
|
+
const requestParams = {
|
|
540
|
+
type: "write",
|
|
541
|
+
to: address,
|
|
542
|
+
from: senderAddress,
|
|
543
|
+
data: serializedData,
|
|
544
|
+
transaction_hash_variant: transactionHashVariant
|
|
545
|
+
};
|
|
546
|
+
const result = await client.request({
|
|
547
|
+
method: "gen_call",
|
|
548
|
+
params: [requestParams]
|
|
549
|
+
});
|
|
550
|
+
const prefixedResult = `0x${result}`;
|
|
551
|
+
if (args.rawReturn) {
|
|
552
|
+
return prefixedResult;
|
|
553
|
+
}
|
|
554
|
+
const resultBinary = _viem.fromHex.call(void 0, prefixedResult, "bytes");
|
|
555
|
+
return decode(resultBinary);
|
|
556
|
+
},
|
|
526
557
|
writeContract: async (args) => {
|
|
527
558
|
const {
|
|
528
559
|
account,
|
|
@@ -612,7 +643,7 @@ var _encodeAddTransactionData = ({
|
|
|
612
643
|
}) => {
|
|
613
644
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
614
645
|
return _viem.encodeFunctionData.call(void 0, {
|
|
615
|
-
abi: _optionalChain([client, 'access',
|
|
646
|
+
abi: _optionalChain([client, 'access', _11 => _11.chain, 'access', _12 => _12.consensusMainContract, 'optionalAccess', _13 => _13.abi]),
|
|
616
647
|
functionName: "addTransaction",
|
|
617
648
|
args: [
|
|
618
649
|
validatedSenderAccount.address,
|
|
@@ -628,7 +659,7 @@ var _encodeSubmitAppealData = ({
|
|
|
628
659
|
txId
|
|
629
660
|
}) => {
|
|
630
661
|
return _viem.encodeFunctionData.call(void 0, {
|
|
631
|
-
abi: _optionalChain([client, 'access',
|
|
662
|
+
abi: _optionalChain([client, 'access', _14 => _14.chain, 'access', _15 => _15.consensusMainContract, 'optionalAccess', _16 => _16.abi]),
|
|
632
663
|
functionName: "submitAppeal",
|
|
633
664
|
args: [txId]
|
|
634
665
|
});
|
|
@@ -640,21 +671,21 @@ var _sendTransaction = async ({
|
|
|
640
671
|
senderAccount,
|
|
641
672
|
value = 0n
|
|
642
673
|
}) => {
|
|
643
|
-
if (!_optionalChain([client, 'access',
|
|
674
|
+
if (!_optionalChain([client, 'access', _17 => _17.chain, 'access', _18 => _18.consensusMainContract, 'optionalAccess', _19 => _19.address])) {
|
|
644
675
|
throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
|
|
645
676
|
}
|
|
646
677
|
const validatedSenderAccount = validateAccount(senderAccount);
|
|
647
678
|
const nonce = await client.getCurrentNonce({ address: validatedSenderAccount.address });
|
|
648
679
|
const transactionRequest = await client.prepareTransactionRequest({
|
|
649
680
|
account: validatedSenderAccount,
|
|
650
|
-
to: _optionalChain([client, 'access',
|
|
681
|
+
to: _optionalChain([client, 'access', _20 => _20.chain, 'access', _21 => _21.consensusMainContract, 'optionalAccess', _22 => _22.address]),
|
|
651
682
|
data: encodedData,
|
|
652
683
|
type: "legacy",
|
|
653
684
|
nonce: Number(nonce),
|
|
654
685
|
value,
|
|
655
686
|
gas: 21000n
|
|
656
687
|
});
|
|
657
|
-
if (_optionalChain([validatedSenderAccount, 'optionalAccess',
|
|
688
|
+
if (_optionalChain([validatedSenderAccount, 'optionalAccess', _23 => _23.type]) !== "local") {
|
|
658
689
|
const formattedRequest = {
|
|
659
690
|
from: transactionRequest.from,
|
|
660
691
|
to: transactionRequest.to,
|
|
@@ -667,7 +698,7 @@ var _sendTransaction = async ({
|
|
|
667
698
|
params: [formattedRequest]
|
|
668
699
|
});
|
|
669
700
|
}
|
|
670
|
-
if (!_optionalChain([validatedSenderAccount, 'optionalAccess',
|
|
701
|
+
if (!_optionalChain([validatedSenderAccount, 'optionalAccess', _24 => _24.signTransaction])) {
|
|
671
702
|
throw new Error("Account does not support signTransaction");
|
|
672
703
|
}
|
|
673
704
|
const serializedTransaction = await validatedSenderAccount.signTransaction(transactionRequest);
|
|
@@ -677,7 +708,7 @@ var _sendTransaction = async ({
|
|
|
677
708
|
throw new Error("Transaction reverted");
|
|
678
709
|
}
|
|
679
710
|
const newTxEvents = _viem.parseEventLogs.call(void 0, {
|
|
680
|
-
abi: _optionalChain([client, 'access',
|
|
711
|
+
abi: _optionalChain([client, 'access', _25 => _25.chain, 'access', _26 => _26.consensusMainContract, 'optionalAccess', _27 => _27.abi]),
|
|
681
712
|
eventName: "NewTransaction",
|
|
682
713
|
logs: receipt.logs
|
|
683
714
|
});
|
|
@@ -890,7 +921,7 @@ var simplifyTransactionReceipt = (tx) => {
|
|
|
890
921
|
var decodeLocalnetTransaction = (tx) => {
|
|
891
922
|
if (!tx.data) return tx;
|
|
892
923
|
try {
|
|
893
|
-
const leaderReceipt = _optionalChain([tx, 'access',
|
|
924
|
+
const leaderReceipt = _optionalChain([tx, 'access', _28 => _28.consensus_data, 'optionalAccess', _29 => _29.leader_receipt]);
|
|
894
925
|
if (leaderReceipt) {
|
|
895
926
|
const receipts = Array.isArray(leaderReceipt) ? leaderReceipt : [leaderReceipt];
|
|
896
927
|
receipts.forEach((receipt) => {
|
|
@@ -921,7 +952,7 @@ var decodeLocalnetTransaction = (tx) => {
|
|
|
921
952
|
}
|
|
922
953
|
});
|
|
923
954
|
}
|
|
924
|
-
if (_optionalChain([tx, 'access',
|
|
955
|
+
if (_optionalChain([tx, 'access', _30 => _30.data, 'optionalAccess', _31 => _31.calldata]) && typeof tx.data.calldata === "string") {
|
|
925
956
|
tx.data.calldata = {
|
|
926
957
|
base64: tx.data.calldata,
|
|
927
958
|
...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
|
|
@@ -984,8 +1015,8 @@ var transactionActions = (client, publicClient) => ({
|
|
|
984
1015
|
return decodeLocalnetTransaction(transaction2);
|
|
985
1016
|
}
|
|
986
1017
|
const transaction = await publicClient.readContract({
|
|
987
|
-
address: _optionalChain([client, 'access',
|
|
988
|
-
abi: _optionalChain([client, 'access',
|
|
1018
|
+
address: _optionalChain([client, 'access', _32 => _32.chain, 'access', _33 => _33.consensusDataContract, 'optionalAccess', _34 => _34.address]),
|
|
1019
|
+
abi: _optionalChain([client, 'access', _35 => _35.chain, 'access', _36 => _36.consensusDataContract, 'optionalAccess', _37 => _37.abi]),
|
|
989
1020
|
functionName: "getTransactionData",
|
|
990
1021
|
args: [
|
|
991
1022
|
hash,
|
|
@@ -1026,7 +1057,7 @@ var connect = async (client, network = "studionet", snapSource = "npm") => {
|
|
|
1026
1057
|
chainName: selectedNetwork.name,
|
|
1027
1058
|
rpcUrls: selectedNetwork.rpcUrls.default.http,
|
|
1028
1059
|
nativeCurrency: selectedNetwork.nativeCurrency,
|
|
1029
|
-
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access',
|
|
1060
|
+
blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _38 => _38.blockExplorers, 'optionalAccess', _39 => _39.default, 'access', _40 => _40.url])]
|
|
1030
1061
|
};
|
|
1031
1062
|
const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
|
|
1032
1063
|
if (currentChainId !== chainIdHex) {
|
|
@@ -1060,10 +1091,10 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1060
1091
|
}
|
|
1061
1092
|
const isFlask = async () => {
|
|
1062
1093
|
try {
|
|
1063
|
-
const clientVersion = await _optionalChain([window, 'access',
|
|
1094
|
+
const clientVersion = await _optionalChain([window, 'access', _41 => _41.ethereum, 'optionalAccess', _42 => _42.request, 'call', _43 => _43({
|
|
1064
1095
|
method: "web3_clientVersion"
|
|
1065
1096
|
})]);
|
|
1066
|
-
return _optionalChain([clientVersion, 'optionalAccess',
|
|
1097
|
+
return _optionalChain([clientVersion, 'optionalAccess', _44 => _44.includes, 'call', _45 => _45("flask")]);
|
|
1067
1098
|
} catch (error) {
|
|
1068
1099
|
console.error("Error detecting Flask:", error);
|
|
1069
1100
|
return false;
|
|
@@ -1071,7 +1102,7 @@ var metamaskClient = async (snapSource = "npm") => {
|
|
|
1071
1102
|
};
|
|
1072
1103
|
const installedSnaps = async () => {
|
|
1073
1104
|
try {
|
|
1074
|
-
return await _optionalChain([window, 'access',
|
|
1105
|
+
return await _optionalChain([window, 'access', _46 => _46.ethereum, 'optionalAccess', _47 => _47.request, 'call', _48 => _48({
|
|
1075
1106
|
method: "wallet_getSnaps"
|
|
1076
1107
|
})]);
|
|
1077
1108
|
} catch (error) {
|
|
@@ -1106,10 +1137,10 @@ function walletActions(client) {
|
|
|
1106
1137
|
function chainActions(client) {
|
|
1107
1138
|
return {
|
|
1108
1139
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
1109
|
-
if (_optionalChain([client, 'access',
|
|
1140
|
+
if (_optionalChain([client, 'access', _49 => _49.chain, 'optionalAccess', _50 => _50.id]) === _chunkZKBMABRAcjs.testnetAsimov.id) {
|
|
1110
1141
|
return;
|
|
1111
1142
|
}
|
|
1112
|
-
if (!forceReset && _optionalChain([client, 'access',
|
|
1143
|
+
if (!forceReset && _optionalChain([client, 'access', _51 => _51.chain, 'access', _52 => _52.consensusMainContract, 'optionalAccess', _53 => _53.address]) && _optionalChain([client, 'access', _54 => _54.chain, 'access', _55 => _55.consensusMainContract, 'optionalAccess', _56 => _56.abi])) {
|
|
1113
1144
|
return;
|
|
1114
1145
|
}
|
|
1115
1146
|
const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
|
|
@@ -1168,11 +1199,11 @@ var getCustomTransportConfig = (config) => {
|
|
|
1168
1199
|
});
|
|
1169
1200
|
const data = await response.json();
|
|
1170
1201
|
if (data.error) {
|
|
1171
|
-
throw
|
|
1202
|
+
throw data.error;
|
|
1172
1203
|
}
|
|
1173
1204
|
return data.result;
|
|
1174
1205
|
} catch (err) {
|
|
1175
|
-
console.error(`Error fetching ${method} from GenLayer RPC
|
|
1206
|
+
console.error(`Error fetching ${method} from GenLayer RPC`);
|
|
1176
1207
|
throw err;
|
|
1177
1208
|
}
|
|
1178
1209
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address, Hex } from 'viem';
|
|
3
3
|
import { G as GenLayerChain } from './chains-BYSCF33g.cjs';
|
|
4
|
-
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-DrEvzYFA.cjs';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_types_authorization from 'viem/_types/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address, Hex } from 'viem';
|
|
3
3
|
import { G as GenLayerChain } from './chains-BYSCF33g.js';
|
|
4
|
-
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
4
|
+
import { G as GenLayerClient, D as DecodedDeployData, a as DecodedCallData, b as GenLayerRawTransaction, c as GenLayerTransaction, C as CalldataEncodable, T as TransactionDataElement } from './index-BIyk5Fv7.js';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
6
|
import * as viem__types_types_authorization from 'viem/_types/types/authorization';
|
|
7
7
|
import * as viem_accounts from 'viem/accounts';
|
package/dist/index.js
CHANGED
|
@@ -523,6 +523,37 @@ var contractActions = (client, publicClient) => {
|
|
|
523
523
|
const resultBinary = fromHex(prefixedResult, "bytes");
|
|
524
524
|
return decode(resultBinary);
|
|
525
525
|
},
|
|
526
|
+
simulateWriteContract: async (args) => {
|
|
527
|
+
const {
|
|
528
|
+
account,
|
|
529
|
+
address,
|
|
530
|
+
functionName,
|
|
531
|
+
args: callArgs,
|
|
532
|
+
kwargs,
|
|
533
|
+
leaderOnly = false,
|
|
534
|
+
transactionHashVariant = "latest-nonfinal" /* LATEST_NONFINAL */
|
|
535
|
+
} = args;
|
|
536
|
+
const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
537
|
+
const serializedData = serialize(encodedData);
|
|
538
|
+
const senderAddress = account?.address ?? client.account?.address;
|
|
539
|
+
const requestParams = {
|
|
540
|
+
type: "write",
|
|
541
|
+
to: address,
|
|
542
|
+
from: senderAddress,
|
|
543
|
+
data: serializedData,
|
|
544
|
+
transaction_hash_variant: transactionHashVariant
|
|
545
|
+
};
|
|
546
|
+
const result = await client.request({
|
|
547
|
+
method: "gen_call",
|
|
548
|
+
params: [requestParams]
|
|
549
|
+
});
|
|
550
|
+
const prefixedResult = `0x${result}`;
|
|
551
|
+
if (args.rawReturn) {
|
|
552
|
+
return prefixedResult;
|
|
553
|
+
}
|
|
554
|
+
const resultBinary = fromHex(prefixedResult, "bytes");
|
|
555
|
+
return decode(resultBinary);
|
|
556
|
+
},
|
|
526
557
|
writeContract: async (args) => {
|
|
527
558
|
const {
|
|
528
559
|
account,
|
|
@@ -1168,11 +1199,11 @@ var getCustomTransportConfig = (config) => {
|
|
|
1168
1199
|
});
|
|
1169
1200
|
const data = await response.json();
|
|
1170
1201
|
if (data.error) {
|
|
1171
|
-
throw
|
|
1202
|
+
throw data.error;
|
|
1172
1203
|
}
|
|
1173
1204
|
return data.result;
|
|
1174
1205
|
} catch (err) {
|
|
1175
|
-
console.error(`Error fetching ${method} from GenLayer RPC
|
|
1206
|
+
console.error(`Error fetching ${method} from GenLayer RPC`);
|
|
1176
1207
|
throw err;
|
|
1177
1208
|
}
|
|
1178
1209
|
}
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-
|
|
2
|
+
export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-DrEvzYFA.cjs';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-BYSCF33g.cjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Account, Address } from 'viem';
|
|
2
|
-
export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-
|
|
2
|
+
export { d as CalldataAddress, C as CalldataEncodable, i as ContractMethod, h as ContractMethodBase, f as ContractParamsArraySchemaElement, g as ContractParamsSchema, j as ContractSchema, a as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, e as GenLayerMethod, b as GenLayerRawTransaction, c as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, k as TransactionHash, s as TransactionHashVariant, m as TransactionResult, p as TransactionResultNameToNumber, l as TransactionStatus, r as TransactionType, V as VoteType, o as transactionResultNumberToName, n as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, q as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-BIyk5Fv7.js';
|
|
3
3
|
export { G as GenLayerChain } from '../chains-BYSCF33g.js';
|
package/package.json
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -70,12 +70,12 @@ const getCustomTransportConfig = (config: ClientConfig) => {
|
|
|
70
70
|
const data = await response.json();
|
|
71
71
|
|
|
72
72
|
if (data.error) {
|
|
73
|
-
throw
|
|
73
|
+
throw data.error
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
return data.result;
|
|
77
77
|
} catch (err) {
|
|
78
|
-
console.error(`Error fetching ${method} from GenLayer RPC
|
|
78
|
+
console.error(`Error fetching ${method} from GenLayer RPC`);
|
|
79
79
|
throw err;
|
|
80
80
|
}
|
|
81
81
|
}
|
package/src/contracts/actions.ts
CHANGED
|
@@ -90,6 +90,50 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
|
|
|
90
90
|
const resultBinary = fromHex(prefixedResult, "bytes");
|
|
91
91
|
return calldata.decode(resultBinary) as any;
|
|
92
92
|
},
|
|
93
|
+
simulateWriteContract: async <RawReturn extends boolean | undefined>(args: {
|
|
94
|
+
account?: Account;
|
|
95
|
+
address: Address;
|
|
96
|
+
functionName: string;
|
|
97
|
+
args?: CalldataEncodable[];
|
|
98
|
+
kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
|
|
99
|
+
rawReturn?: RawReturn;
|
|
100
|
+
leaderOnly?: boolean;
|
|
101
|
+
transactionHashVariant?: TransactionHashVariant;
|
|
102
|
+
}): Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable> => {
|
|
103
|
+
const {
|
|
104
|
+
account,
|
|
105
|
+
address,
|
|
106
|
+
functionName,
|
|
107
|
+
args: callArgs,
|
|
108
|
+
kwargs,
|
|
109
|
+
leaderOnly = false,
|
|
110
|
+
transactionHashVariant = TransactionHashVariant.LATEST_NONFINAL,
|
|
111
|
+
} = args;
|
|
112
|
+
|
|
113
|
+
const encodedData = [calldata.encode(calldata.makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
|
|
114
|
+
const serializedData = serialize(encodedData);
|
|
115
|
+
|
|
116
|
+
const senderAddress = account?.address ?? client.account?.address;
|
|
117
|
+
|
|
118
|
+
const requestParams = {
|
|
119
|
+
type: "write",
|
|
120
|
+
to: address,
|
|
121
|
+
from: senderAddress,
|
|
122
|
+
data: serializedData,
|
|
123
|
+
transaction_hash_variant: transactionHashVariant,
|
|
124
|
+
};
|
|
125
|
+
const result = await client.request({
|
|
126
|
+
method: "gen_call",
|
|
127
|
+
params: [requestParams],
|
|
128
|
+
});
|
|
129
|
+
const prefixedResult = `0x${result}` as `0x${string}`;
|
|
130
|
+
|
|
131
|
+
if (args.rawReturn) {
|
|
132
|
+
return prefixedResult;
|
|
133
|
+
}
|
|
134
|
+
const resultBinary = fromHex(prefixedResult, "bytes");
|
|
135
|
+
return calldata.decode(resultBinary) as any;
|
|
136
|
+
},
|
|
93
137
|
writeContract: async (args: {
|
|
94
138
|
account?: Account;
|
|
95
139
|
address: Address;
|
package/src/types/clients.ts
CHANGED
|
@@ -59,6 +59,16 @@ export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
|
|
|
59
59
|
leaderOnly?: boolean;
|
|
60
60
|
consensusMaxRotations?: number;
|
|
61
61
|
}) => Promise<any>;
|
|
62
|
+
simulateWriteContract: <RawReturn extends boolean | undefined>(args: {
|
|
63
|
+
account?: Account;
|
|
64
|
+
address: Address;
|
|
65
|
+
functionName: string;
|
|
66
|
+
args?: CalldataEncodable[];
|
|
67
|
+
kwargs?: Map<string, CalldataEncodable> | { [key: string]: CalldataEncodable };
|
|
68
|
+
rawReturn?: RawReturn;
|
|
69
|
+
leaderOnly?: boolean;
|
|
70
|
+
transactionHashVariant?: TransactionHashVariant;
|
|
71
|
+
}) => Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable>;
|
|
62
72
|
deployContract: (args: {
|
|
63
73
|
account?: Account;
|
|
64
74
|
code: string | Uint8Array;
|