#Sign a contract xdr from vanilla Js

9 messages · Page 1 of 1 (latest)

mighty scroll
#

Does anyone or has anyone been able to sign a contract method with arguements transaction xdr using vanilla Js with freighter wallet from the testnet.

Anytime I try, I keep getting invalid xdr

#

My code

const stellarServer = "https://soroban-testnet.stellar.org"
const stellarServer_1 = "https://horizon-testnet.stellar.org"
const stellarServer_2 = "https://soroban-testnet.stellar.org:44"
const daoContractId = "CCGBC2P2HEXU37JNY5RKFZLKZ4G6LMRW7TFHA6ZTRA6BRDXQCTM2VJ2Y"
@if (isset($_COOKIE['wallet']))
const walletAddress = "{{ $_COOKIE['public'] }}"
@else
const walletAddress = ""
@endif
// console.log(window)
//SET UP FUNCTION
const createDaos = async () => {
if(walletAddress != "") {
const server = new SorobanClient.Server(stellarServer);
const account = await server.getAccount(walletAddress);
const fee = 100;
const contract = new SorobanClient.Contract(daoContractId);
let _walletAdr = new SorobanClient.Address(walletAddress)
_walletAdr = _walletAdr.toScVal()
let _tokenAdr = new SorobanClient.Address("CCXHCCDBUJ34KHSFOTMY7SLPBHBRG346BTSTBBT5RJKA22LG6G7UXG6J")
_tokenAdr = _tokenAdr.toScVal()
const _name = SorobanClient.nativeToScVal("DAO")

         let transaction = new SorobanClient.TransactionBuilder(account, { fee, networkPassphrase: SorobanClient.Networks.TESTNET })
            .addOperation(
                // An operation to call increment on the contract
                contract.call("increment", _walletAdr, _tokenAdr, _name)
            )
             .setTimeout(30)
// Uncomment to add a memo (https://developers.stellar.org/docs/glossary/transactions/)
// .addMemo(SorobanClient.Memo.text('Hello world!'))
.build();
   
       
        transaction = await server.prepareTransaction(transaction);
        const xdrEnvelope = await transaction.toEnvelope().toXDR('base64');

        console.log( await window.freighterApi.signTransaction('xdrEnvelope', "TESTNET"))

Operations and transactions: how they work

burnt beacon
#

it should be Networks.TESTNET for the correct network passphrase

ember minnow
#

that looks correct

mighty scroll
#

I am not using nodeJs. I am using freighter in the browser

mighty scroll
#

XDR Read Error: unknown ScValType member for value -1945015814

This is what freighter returns everytime

ember minnow
#

Can you share your code we will help

mighty scroll
#

We been able to solve it. There is a bug with the freighter wallet