Methods

The dApp api is in alpha, please join our Discord to follow the latest updates or email Dimitry.

Connect Wallet

const accounts = await window.chia.request({ method: "requestAccounts" });
console.log(accounts?.[0]))

Get chainId

window.chia.request({ method: 'chainId' })

Get Current Accounts

const accounts = await window.chia.request({ method: "accounts" });
console.log(accounts?.[0]))

Switch chains

const params = {
chainId: '0x01', // '0x02'
}
window.chia.request({ method: 'walletSwitchChain', params })

Transfer

const params = {
"to": "xch1458padpp4yw30nz9r63z9ty0ay7ju7xg8z0gjq2ekxumapmgprpqtaum28",
"amount": "100000000",
"memos": [],
"assetId": "",
};
window.chia.request({ method: "transfer", params });

Take offer

window.chia.request({method: 'takeOffer', params: {offer: 'offerxxxx'})

Create offer

const params = {
requestAssets: [
{
amount: 1000,
assetId: '',
},
],
offerAssets: [
{
assetId:
'c5de266e7ec6ab97e3ab6d6d11719ae3b35ee252bbcd6244524109b4503e846a',
amount: 100000,
},
],
}
window.chia.request({ method: 'createOffer', params })
// nft example, offer 1xch reqeust nft
window.chia.request({
method: 'createOffer',
params: {
requestAssets: [
{
assetId: 'nft1xqertsxveqgs23gh99d66sz28tnd6uv6ewqwas03rfulp56wel4qhscljk',
amount: 1
}
],
offerAssets: [
{
assetId: '',
amount: 1000000000000
}
]
}
})

Typescript Interface

type Amount = string | number;
type HexString = string;
export interface Coin {
parent_coin_info: string;
puzzle_hash: string;
amount: number;
}
export interface CoinSpend {
coin: Coin;
puzzle_reveal: HexString
solution: HexString
}
export interface SpendBundle {
coin_spends: CoinSpend[]
aggregated_signature: HexString
}
interface TakeOfferParams {
offer: string;
}
interface AssetAmount {
assetId: string;
amount: Amount,
}
interface TransferParams {
to: string;
amount: Amount;
assetId: string;
memos?: HexString[];
}
interface CreateOfferParams {
offerAssets: AssetAmount[];
requestAssets: AssetAmount[];
fee?: number; // mojo
}
export interface Wallet {
accounts(): Promise<string[]>
chainId(): Promise<string>
requestAccounts(): Promise<string[]>
walletSwitchChain(params: {chainId: string}): Promise<null>
transfer(params: TransferParams): Promise<{
id: string;
}>
takeOffer(params: TakeOfferParams): Promise<{
id: string;
}>
createOffer(params: CreateOfferParams): Promise<{
id: string;
offer: string;
}>
}