stellar / js-soroban-client

Main Soroban client library for the Javascript language
https://stellar.github.io/js-soroban-client/
Apache License 2.0
22 stars 17 forks source link

js-soroban-sdk: transaction simulation failed #165

Closed lush-onion closed 10 months ago

lush-onion commented 1 year ago

Describe the bug I get an error transaction simulation failed when I simulate a transaction with one of operations restoreFootprint or bumpFootprintExpiration by method prepareTransaction. However, the simulation works correctly directly using fetch

What version are you on? "soroban-client": "1.0.0-beta.3",

Creating a transaction:

getRestoreContractTx(publicKey: string, contract: Contract) {
      return this.server
            .getAccount(publicKey)
            .then((acc) => {
                return new SorobanClient.TransactionBuilder(acc, {
                    fee: BASE_FEE,
                    networkPassphrase: SorobanClient.Networks.TESTNET,
                })
                    .addOperation(SorobanClient.Operation.restoreFootprint({}))
                    .setSorobanData(
                        new SorobanClient.SorobanDataBuilder()
                            .setReadWrite([contact.getFootprint()[1]])
                            .build(),
                    )
                    .setTimeout(SorobanClient.TimeoutInfinite)
                    .build();
            })
    }

If I call the prepareTransaction from sdk I get an error transaction simulation failed

But if I do this, everything works:

prepareByFetch(tx): Promise<SorobanClient.Transaction> {
        const xdr = tx.toXDR();

        const requestObject = {
            jsonrpc: '2.0',
            method: 'simulateTransaction',
            id: 0,
            params: {
                transaction: xdr,
            },
        };

        return fetch(SOROBAN_SERVER, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(requestObject),
        })
            .then((res) => res.json())
            .then(({ result }) => {
                return assembleTransaction(tx, SorobanClient.Networks.TESTNET, result).build();
            });
    }