Options
All
  • Public
  • Public/Protected
  • All
Menu

The main class that exposes all Wallet Connect operations to allow such interaction. It exposes static methods and instance methods, is up to the developer to choose which approach fits better it's needs.

// you can call the constructor to have an instance with it's own state
const wcInstance = new WcSdk()
// and call the methods directly from it, eg.:
wcInstance.initClient(...)
wcInstance.loadSession(...)

// Or alternatively you can use the static methods and store the wcClient and session by yourself, eg.:
const wcClient = WcSdk.initClient(...)
const session = wcInstance.loadSession(...)
// the downside of this approach is that you will have to pass wcClient and session as parameter on most of the methods

Hierarchy

  • WcSdk

Index

Constructors

constructor

Properties

Optional session

session?: Settled

The Session of the current connection

Optional wcClient

wcClient?: Client

Wallet Connect Client, used on most of the methods

Accessors

accountAddress

  • get accountAddress(): string
  • gets the address of the first connected account, to retrieve this information from another account use getAccountAddress method.

    Returns string

    a string that represents the blockchain

chainId

  • get chainId(): string
  • gets the chain id of the first connected account, to retrieve this information from another account use WcSdk.getAccountInfo static method.

    Returns string

    a string that represents the blockchain

Methods

connect

  • Start the process of establishing a new connection, to be used when there is no wcInstance.session

    Parameters

    Returns Promise<void>

disconnect

  • disconnect(): Promise<void>
  • Disconnects from the Wallet, use this method to logout

    Returns Promise<void>

getAccountAddress

  • getAccountAddress(accountIndex?: number): string
  • gets the address of the connected account

    Parameters

    • Optional accountIndex: number

      the index of the account to retrieve, gets the first account if no index is provided

    Returns string

    the address of the connected account of the wallet

initClient

  • initClient(logger: string, relayServer: string): Promise<void>
  • Initializes the SDK, it's the first method to be called

    Parameters

    • logger: string

      the logger level, describes how much information to show on the log, use debug for more information or error for less information

    • relayServer: string

      the relayserver to connect to, it needs to be the same relay server of the wallet. It's recommended to use wss://relay.walletconnect.org

    Returns Promise<void>

invokeFunction

  • Sends an 'invokeFunction' request to the Wallet and it will communicate with the blockchain. It will consume gas and persist data to the blockchain. For reference, developers should reference the contract manifest on the contracts details pages on dora to understand the methods and argument types needed. For this example: GAS

    ``` const senderAddress = wcInstance.getAccountAddress()

    const invocation: ContractInvocation = { scriptHash: '0xd2a4cff31913016155e38e474a2c06d08be276cf', operation: 'transfer', args: [ { type: 'Address', value: senderAddress }, { type: 'Address', value: 'NbnjKGMBJzJ6j5PHeYhjJDaQ5Vy5UYu4Fv' }, { type: 'Integer', value: 100000000 }, { type: 'Array', value: [] } ] }

    const signer: Signer = { scopes: WitnessScope.Global }

    const resp = await wcInstance.invokeFunction(invocation, signer)

    
    

    Parameters

    Returns Promise<RpcCallResult<any>>

    the call result promise. It might only contain the transactionId, another call to the blockchain might be necessary to check the result.

loadSession

  • loadSession(): Promise<void>
  • Load any existing connection, it should be called after the initialization, to reestablish connections made previously

    Returns Promise<void>

sendRequest

  • Sends a request to the Wallet and it will call the RpcServer

    const result = await wcInstance.sendRequest({
    method: 'getapplicationlog',
    params: ['0x7da6ae7ff9d0b7af3d32f3a2feb2aa96c2a27ef8b651f9a132cfaad6ef20724c']
    })

    Parameters

    • request: MethodAndParams

      the request information object containing the rpc method name and the parameters

    Returns Promise<RpcCallResult<any>>

    the call result promise

signMessage

  • Sends a signMessage request to the Wallet. Signs a message

    Parameters

    • message: string

      the message to be signed

    Returns Promise<RpcCallResult<SignedMessage>>

    the signed message object

subscribeToEvents

  • Subscribe to Wallet Connect events

    wcInstance.subscribeToEvents({
    onProposal: (uri: string) => {
    // show the QRCode, you can use @walletconnect/qrcode-modal to do so, but any QRCode presentation is fine
    QRCodeModal.open(uri, () => {})
    // alternatively you can show Neon Wallet Connect's website, which is more welcoming
    window.open(`https://neon.coz.io/connect?uri=${uri}`, '_blank').focus();
    },
    onDeleted: () => {
    // here is where you describe a logout callback
    logout()
    }
    })

    Parameters

    Returns void

testInvoke

  • Sends a testInvoke request to the Wallet and it will communicate with the blockchain. It will not consume any gas but it will also not persist any data, this is often used to retrieve SmartContract information or check how much gas an invocation will cost. Also, the wallet might choose to not ask the user authorization for test invocations making them easy to use. For reference, developers should reference the contract manifest on the contracts details pages on dora to understand the methods and argument types needed. For this example: Crypsydra (testnet)

    const signer: Signer = {
    scopes: 128
    }

    const invocation: ContractInvocation = {
    scriptHash: '0x010101c0775af568185025b0ce43cfaa9b990a2a',
    operation: 'getStream',
    args: [{ type: 'Integer', value: 17 }]
    }

    const resp = await wcInstance.testInvoke(invocation, signer)

    Parameters

    Returns Promise<RpcCallResult<any>>

    the call result promise

verifyMessage

  • Sends a verifyMessage request to the Wallet. Checks if the signedMessage is true

    Parameters

    • signedMessage: SignedMessage

      an object that represents a signed message

    Returns Promise<RpcCallResult<boolean>>

    true if the signedMessage is acknowledged by the account

Static certifyInvocationPayload

Static connect

  • Start the process of establishing a new connection, to be used when there is no wcInstance.session

    Parameters

    • wcClient: Client
    • options: WcConnectOptions

      describes the options for the connection

    Returns Promise<Settled>

Static disconnect

  • disconnect(wcClient: Client, session: Settled): Promise<void>
  • Disconnects from the Wallet, use this method to logout

    Parameters

    • wcClient: Client
    • session: Settled

      connected session

    Returns Promise<void>

Static getAccountAddress

  • getAccountAddress(session: Settled, accountIndex?: number): string
  • gets the address of the connected account

    Parameters

    • session: Settled

      connection session

    • Optional accountIndex: number

      the index of the account to retrieve, gets the first account if no index is provided

    Returns string

    the address of the connected account of the wallet

Static getAccountInfo

  • getAccountInfo(session: Settled, accountIndex?: number): string[]
  • gets the information of a connected account

    Parameters

    • session: Settled

      connection session

    • Optional accountIndex: number

      index of one of the connected accounts

    Returns string[]

    an array that represents the address and chain

Static getChainId

  • getChainId(session: Settled, accountIndex?: number): string
  • gets the chain id of the first connected account, to retrieve this information from another account use WcSdk.getAccountInfo static method.

    Parameters

    • session: Settled

      connection session

    • Optional accountIndex: number

      the index of the account to retrieve, gets the first account if no index is provided

    Returns string

    a string that represents the blockchain

Static getSession

  • getSession(wcClient: Client): Promise<Settled>
  • Gets any existing connection, it should be called after the initialization, to retrieve the session of connections made previously

    Parameters

    • wcClient: Client

    Returns Promise<Settled>

Static initClient

  • initClient(logger: string, relayProvider: string): Promise<Client>
  • Initializes the SDK, it's the first method to be called

    Parameters

    • logger: string

      the logger level, describes how much information to show on the log, use debug for more information or error for less information

    • relayProvider: string

      the relayProvider to connect to, it needs to be the same relay server of the wallet. It's recommended to use wss://relay.walletconnect.org

    Returns Promise<Client>

    a wcClient

Static invokeFunction

  • Sends an 'invokeFunction' request to the Wallet and it will communicate with the blockchain. It will consume gas and persist data to the blockchain.

    const senderAddress = WcSdk.getAccountAddress(session)

    const invocations: ContractInvocation[] = [
    {
    scriptHash: '0x010101c0775af568185025b0ce43cfaa9b990a2a',
    operation: 'getStream',
    abortOnFail: true, // if 'getStream' returns false the next invocation will not be made
    args: [
    { type: 'Integer', value: 17 }
    ]
    },
    {
    scriptHash: '0x010101c0775af568185025b0ce43cfaa9b990a2a',
    operation: 'transfer',
    args: [
    { type: 'Address', value: senderAddress },
    { type: 'Address', value: 'NbnjKGMBJzJ6j5PHeYhjJDaQ5Vy5UYu4Fv' },
    { type: 'Integer', value: 100000000 },
    { type: 'Array', value: [] }
    ]
    }
    ]

    const signer: Signer[] = [
    {
    scopes: WitnessScope.Global
    }
    ]

    const formattedRequest: ContractInvocationMulti = {
    signer,
    invocations
    }
    const resp = await WcSdk.invokeFunction(wcClient, session, chainId, formattedRequest)

    Parameters

    • wcClient: Client
    • session: Settled

      connected session

    • chainId: string

      the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet

    • request: ContractInvocationMulti

      the contract invocation options

    Returns Promise<RpcCallResult<any>>

    the call result promise. It might only contain the transactionId, another call to the blockchain might be necessary to check the result.

Static objectValidation

  • objectValidation(object: any, keys: string[]): boolean
  • Parameters

    • object: any
    • keys: string[]

    Returns boolean

Static sendRequest

  • Sends a request to the Wallet and it will call the RpcServer

    const result = await WcSdk.sendRequest(wcClient, session, chainId, {
    method: 'getapplicationlog',
    params: ['0x7da6ae7ff9d0b7af3d32f3a2feb2aa96c2a27ef8b651f9a132cfaad6ef20724c']
    })

    Parameters

    • wcClient: Client
    • session: Settled

      connected session

    • chainId: string

      the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet

    • request: MethodAndParams

      the request information object containing the rpc method name and the parameters

    Returns Promise<RpcCallResult<any>>

    the call result promise

Static signMessage

  • Sends a signMessage request to the Wallet. Signs a message

    Parameters

    • wcClient: Client
    • session: Settled

      connected session

    • chainId: string

      the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet

    • message: string

      the message to be signed

    Returns Promise<RpcCallResult<SignedMessage>>

    the signed message object

Static subscribeToEvents

  • subscribeToEvents(wcClient?: Client, callbacks?: WcCallbacks): void
  • Subscribe to Wallet Connect events

    WcSdk.subscribeToEvents(wcClient, {
    onProposal: (uri: string) => {
    // show the QRCode, you can use @walletconnect/qrcode-modal to do so, but any QRCode presentation is fine
    QRCodeModal.open(uri, () => {})
    // alternatively you can show Neon Wallet Connect's website, which is more welcoming
    window.open(`https://neon.coz.io/connect?uri=${uri}`, '_blank').focus();
    },
    onDeleted: () => {
    // here is where you describe a logout callback
    logout()
    }
    })

    Parameters

    • Optional wcClient: Client
    • Optional callbacks: WcCallbacks

    Returns void

Static testInvoke

  • Sends a testInvoke request to the Wallet and it will communicate with the blockchain. It will not consume any gas but it will also not persist any data, this is often used to retrieve SmartContract information or check how much gas an invocation will cost. Also, the wallet might choose to not ask the user authorization for test invocations making them easy to use.

    const senderAddress = WcSdk.getAccountAddress(session)

    const signers: Signer[] = [
    {
    scopes: WitnessScope.None
    }
    ]

    const invocations: ContractInvocation[] = [
    {
    scriptHash: '0x010101c0775af568185025b0ce43cfaa9b990a2a',
    operation: 'getStream',
    abortOnFail: true, // if 'getStream' returns false the next invocation will not be made
    args: [
    { type: 'Integer', value: 17 }
    ],
    },
    {
    scriptHash: '0x010101c0775af568185025b0ce43cfaa9b990a2a',
    operation: 'balanceOf',
    args: [
    { type: 'Address', value: senderAddress }
    ]
    }
    ]

    const formattedRequest: ContractInvocationMulti = {
    signers,
    invocations
    }
    const resp = await WcSdk.testInvoke(wcClient, session, chainId, formattedRequest)

    Parameters

    • wcClient: Client
    • session: Settled

      connected session

    • chainId: string

      the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet

    • request: ContractInvocationMulti

      the contract invocation options

    Returns Promise<RpcCallResult<any>>

    the call result promise

Static verifyMessage

  • Sends a verifyMessage request to the Wallet. Checks if the signedMessage is true

    Parameters

    • wcClient: Client
    • session: Settled

      connected session

    • chainId: string

      the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet

    • signedMessage: SignedMessage

      an object that represents a signed message

    Returns Promise<RpcCallResult<boolean>>

    true if the signedMessage is acknowledged by the account

Generated using TypeDoc