GitHub: https://github.com/FunctionX/fx-js-sdk
fxwallet version (minimum): v2.0
WalletConnectId: 39778
CHAIN_ID: fxevm
Like the python SDK, Function X's JavaScript SDK: fx-js-sdk
, can also be used to prototype, develop, and deploy blockchain solutions using JavaScript.
{% code lineNumbers="true" %}
export function getAccountRequest(chainIds) {
return {
id: payloadId(),
jsonrpc: '2.0',
method: 'functionx_wc_accounts_v1',
params: chainIds,
};
}
{% endcode %}
{% code lineNumbers="true" %}
const request = getAccountRequest([CHAIN_ID,CHAIN_ID]);
connector.sendCustomRequest(request)
.then((accounts) => {
setAccounts(accounts);
console.log(accounts.length == 1);
}).catch((error) => {
console.error(error);
});
{% endcode %}
[name, algo, publicKey, addressByte, bech32Address]
Sign transaction using FunctionX Mobile Wallet via Wallet Connect
- signer:
bech32Address
{% code lineNumbers="true" %}
import {
makeSignDoc as makeAminoSignDoc,
serializeSignDoc
} from "@cosmjs/amino"
import { fromUtf8 } from "@cosmjs/encoding"
const signDoc = makeAminoSignDoc(messages, fee, chainId, memo, accountNumber, sequence)
const signBytes = serializeSignDoc(signDoc)
const signData = fromUtf8(signBytes)
connector.sendCustomRequest({
id: payloadId(),
jsonrpc: '2.0',
method: 'functionx_wc_sign_tx_v1',
params: [chainId, signer, signData],
})
.then((response) => {
const signed = _.get(response, '0.signed');
const signature = _.get(response, '0.signature');
return broadcastTx(signed, signature);
}).then((result) => {
const code = _.get(result, 'code');
if (code === 0) {
const txHash = _.get(result, 'txhash');
console.log(txHash);
} else {
const rawLog = _.get(result, 'raw_log');
console.error(rawLog);
}
})
{% endcode %}