Methods

Goby implements all the methods defined in CHiP-0002 and preseres some methods exposed before.

Transfer

const params = {
"to": "xch1458padpp4yw30nz9r63z9ty0ay7ju7xg8z0gjq2ekxumapmgprpqtaum28",
"amount": "100000000",
"memos": ["0x68656c6c6f2063686961", ], // hex string, "hello chia".encode("utf-8)
"assetId": "",
};
window.chia.request({ method: "transfer", params });
# how to encode the memo
function toHex(txt) {
const encoder = new TextEncoder();
return Array
.from(encoder.encode(txt))
.map(b => b.toString(16).padStart(2, '0'))
.join('')
}
toHex('hello world')

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
}
]
}
})

walletWatchAsset

const params = {
type: 'cat',
options: {
assetId: '6d95dae356e32a71db5ddcb42224754a02524c615c5fc35f568c2af04774e589',
symbol: 'USDS',
logo: 'https://static.goby.app/image/token/usds/USDS_32.png'
}
}
window.chia.request({ method: 'walletWatchAsset', params })

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 AssetBalanceResp {
confirmed: string;
spendable: string;
spendableCoinCount: number;
}
interface getAssetCoinsParams {
type: string|null;
assetId?: string|null;
includedLocked?: boolean;
offset?: number;
limit?: number;
}
interface sendTransactionParams {
spendBundle: SpendBundle;
}
// stay the same as [transaction_ack](https://docs.chia.net/docs/10protocol/wallet_protocol/#transaction_ack)
enum MempoolInclusionStatus {
SUCCESS = 1, // Transaction added to mempool
PENDING = 2, // Transaction not yet added to mempool
FAILED = 3 // Transaction was invalid and dropped
}
interface TransactionResp {
status: MempoolInclusionStatus;
error?: string;
}
interface SignMessageParams {
message: string;
publicKey: string;
}
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
}
interface WatchAssetParams {
type: string; // 'cat'
options: {
assetId: string;
symbol: string;
logo?: string;
}
}
export interface Wallet {
chainId(): Promise<string>
filterUnlockedCoins(params: {coinNames: string[]}): Promise<string[]>
walletSwitchChain(params: {chainId: string}): Promise<null>
connect(params?: {eager?: boolean}): Promise<boolean>
getPublicKeys(params?: {limit?: number, offset?: number}): Promise<string[]>
signCoinSpends(params: {coinSpends: CoinSpend[]}): Promise<string>
getAssetBalance(params: {type: string|null, assetId: string|null}): Promise<AssetBalanceResp>
getAssetCoins(params: getAssetCoinsParams): Promise<SpendableCoin[]>
sendTransaction(params: sendTransactionParams): Promise<TransactionResp[]>
signMessage(params: SignMessageParams): Promise<string>
transfer(params: TransferParams): Promise<{
id: string;
}>
takeOffer(params: TakeOfferParams): Promise<{
id: string;
}>
createOffer(params: CreateOfferParams): Promise<{
id: string;
offer: string;
}>
walletWatchAsset (params: WatchAssetParams): Promise<boolean>
}