Hello,
has anybody successfully created a smart contract using Ledger Nano S for signing the transaction object? I'm trying to create the contract from a dapp and when calling Ledger SDK's str.signTransaction to sign the transaction then instead of being asked to approve it on the ledger app I receive the error "Ledger device: UNKNOWN_ERROR (0xb005)".
A standard payment operation can be signed on the Ledger app successfully though, also signing the very same transaction with other wallets like Freighter or Albedo works fine as well. So maybe it's a limitation of the stellar ledger app or the ledger SDK.
import Transport from "@ledgerhq/hw-transport-webusb";
import Str from "@ledgerhq/hw-app-str";
const sorobanRpc = new SorobanRpc.Server('https://soroban-testnet.stellar.org');
// get the first ledger account for signing
const transport = await Transport.create();
const str = new Str(transport);
const keyPath = "44'/148'/0'";
const key = await str.getPublicKey(keyPath);
const senderAddress = key.publicKey;
const account = await sorobanRpc.getAccount(senderAddress);
// hash of the already installed WASM code on TESTNET
const wasmHashHex = "7f7c3e89d2380f6e8e43eb418657436c491581cf2acbaa9ae4853a21c26bf859";
const wasmHash = hexToRawBytes(wasmHashHex);
// signing of this InvokeHostFunction operation fails later on the Ledger Nano app
const createCustomContractOp = Operation.createCustomContract({
wasmHash: Buffer.from(wasmHash),
address: Address.fromString(senderAddress),
salt: crypto.getRandomValues(Buffer.alloc(32)),
});
// trx object for it
const createContractTrx: Transaction = new TransactionBuilder(account, {
fee: BASE_FEE,
networkPassphrase: Networks.TESTNET
})
.addOperation(createCustomContractOp)
.setTimeout(30)
.build();
let fails = await str.signTransaction(keyPath, createContractTrx.signatureBase()); // this fails with error "Ledger device: UNKNOWN_ERROR (0xb005)"