#Invoking smart contract with address value from frontend

4 messages · Page 1 of 1 (latest)

stark badger
#

I am having problem with invoking deploy() function from frontend. I am using typescript binding of deployer contract

    const ownerAddr = new Address("GD75OZRV62DYS6RMUCVUIYWKZ2BTP2WMSOFNCPEOJPYHYFIYRCE6SHCD")
    const routerAddr = new Address("CACIQ6HWPBEMPQYKRRAZSM6ZQORTBTS7DNXCRTI6NQYMUP2BHOXTBUVD")
const handleDeploy = async () => {
        const deploy = await DeployerClient.default.deploy({
            wasm_hash: Buffer.from(wasmHash, 'hex'),
            salt: Buffer.from("4b230010c1dc15dfd0e52e4ef874906dbe4ba5c362593595725e3b2d9c9511cb", 'hex'),
            constructor_args: [ownerAddr.toScVal(), routerAddr.toScVal()]
        })
    }

Above is resulting in a console error:

Uncaught (in promise) TypeError: cannot interpret n2 value as ScVal ({"_switch":{"name":"scvAddress","value":18},"_arm":"address","_value":{"_switch":{"name":"scAddressTypeAccount","value":0},"_arm":"accountId","_value":{"_switch":{"name":"publicKeyTypeEd25519","value":0},"_arm":"ed25519","_armType":{"_length":32},"_value":{"type":"Buffer","data":[255,215,102,53,246,135,137,122,44,160,171,68,98,202,206,131,55,234,204,147,138,209,60,142,75,240,124,21,24,136,137,233]}}}})
    at Spec2.nativeToScVal (spec.js:667:21)
    at spec.js:610:37
    at Array.map (<anonymous>)
    at Spec2.nativeToScVal (spec.js:609:62)
    at spec.js:506:22
    at Array.map (<anonymous>)
    at Spec2.funcArgsToScVals (spec.js:505:26)
    at Client.assembleTransaction2 [as deploy] (client.js:129:30)
    at Object.handleDeploy [as onClick] (Welcome.tsx:43:53)
    at onClick (index.tsx:109:25)

What is the correct way to pass this constructor_args for deploy function

#
export interface Client {
    /**
     * Construct and simulate a deploy transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
     * Deploys the contract on behalf of the `Deployer` contract.
     */
    deploy: ({ wasm_hash, salt, constructor_args }: {
        wasm_hash: Buffer;
        salt: Buffer;
        constructor_args: Array<any>;
    }, options?: {
        /**
         * The fee to pay for the transaction. Default: BASE_FEE
         */
        fee?: number;
        /**
         * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
         */
        timeoutInSeconds?: number;
        /**
         * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
         */
        simulate?: boolean;
    }) => Promise<AssembledTransaction<string>>;
    /**
     * Construct and simulate a get_admin transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
     */
    get_admin: (options?: {
        /**
         * The fee to pay for the transaction. Default: BASE_FEE
         */
        fee?: number;
        /**
         * The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
         */
        timeoutInSeconds?: number;
        /**
         * Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
         */
        simulate?: boolean;
    }) => Promise<AssembledTransaction<string>>;
}

Deployer contract typescipt binding has deploy function interface as above.

winter surge
stark badger