The Session of the current connection
Wallet Connect Client, used on most of the methods
gets the address of the first connected account, to retrieve this information from another account use getAccountAddress
method.
a string that represents the blockchain
gets the chain id of the first connected account, to retrieve this information from another account use WcSdk.getAccountInfo
static method.
a string that represents the blockchain
Start the process of establishing a new connection, to be used when there is no wcInstance.session
describes the options for the connection
Disconnects from the Wallet, use this method to logout
gets the address of the connected account
the index of the account to retrieve, gets the first account if no index is provided
the address of the connected account of the wallet
Initializes the SDK, it's the first method to be called
the logger level, describes how much information to show on the log, use debug
for more information or error
for less information
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
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)
the contract invocation options
the call result promise. It might only contain the transactionId, another call to the blockchain might be necessary to check the result.
Load any existing connection, it should be called after the initialization, to reestablish connections made previously
Sends a request to the Wallet and it will call the RpcServer
const result = await wcInstance.sendRequest({
method: 'getapplicationlog',
params: ['0x7da6ae7ff9d0b7af3d32f3a2feb2aa96c2a27ef8b651f9a132cfaad6ef20724c']
})
the request information object containing the rpc method name and the parameters
the call result promise
Sends a signMessage
request to the Wallet.
Signs a message
the message to be signed
the signed message object
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()
}
})
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)
The contract invocation options. For multiple invocations, pass an array.
the call result promise
Sends a verifyMessage
request to the Wallet.
Checks if the signedMessage is true
an object that represents a signed message
true if the signedMessage is acknowledged by the account
Verifies a contract invocation payload
Start the process of establishing a new connection, to be used when there is no wcInstance.session
describes the options for the connection
Disconnects from the Wallet, use this method to logout
connected session
gets the address of the connected account
connection session
the index of the account to retrieve, gets the first account if no index is provided
the address of the connected account of the wallet
gets the information of a connected account
connection session
index of one of the connected accounts
an array that represents the address and chain
gets the chain id of the first connected account, to retrieve this information from another account use WcSdk.getAccountInfo
static method.
connection session
the index of the account to retrieve, gets the first account if no index is provided
a string that represents the blockchain
Gets any existing connection, it should be called after the initialization, to retrieve the session of connections made previously
Initializes the SDK, it's the first method to be called
the logger level, describes how much information to show on the log, use debug
for more information or error
for less information
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
a wcClient
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)
connected session
the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet
the contract invocation options
the call result promise. It might only contain the transactionId, another call to the blockchain might be necessary to check the result.
Sends a request to the Wallet and it will call the RpcServer
const result = await WcSdk.sendRequest(wcClient, session, chainId, {
method: 'getapplicationlog',
params: ['0x7da6ae7ff9d0b7af3d32f3a2feb2aa96c2a27ef8b651f9a132cfaad6ef20724c']
})
connected session
the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet
the request information object containing the rpc method name and the parameters
the call result promise
Sends a signMessage
request to the Wallet.
Signs a message
connected session
the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet
the message to be signed
the signed message object
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()
}
})
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)
connected session
the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet
the contract invocation options
the call result promise
Sends a verifyMessage
request to the Wallet.
Checks if the signedMessage is true
connected session
the chosen blockchain id to make the request, must be one of the blockchains authorized by the wallet
an object that represents a signed message
true if the signedMessage is acknowledged by the account
Generated using TypeDoc
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.