Skip to content

StarkNet

When running a DApp in the Bitget Wallet App or Chrome browser with the installed Chrome Extension, you can obtain the global object window.bitkeep.starkstarknet_bitkeepnet and make subsequent API calls.

js
const provider = window.starknet_bitkeep; // Recommended method
const provider = window.starknet;
const provider = window.starknet_bitkeep; // Recommended method
const provider = window.starknet;

Injected Object Properties and Methods

  • name - string: Wallet name, value is 'Bitget Wallet'.
  • icon - string: Wallet icon
  • version - string: Version number
  • chainId - string: Only supports mainnet, value is SN_MAIN
  • isConnected - boolean: Whether the current wallet is connected
  • selectedAddress - string: The currently selected wallet address
  • account - Account: Access the account object, inherited from starknet.js's Account. For specific properties and methods on the instance, refer to starknet.js documentation.
  • provider - Provider: Access the provider object, using starknet.js's RpcProvider. For specific properties and methods on the instance, refer to starknet.js documentation.
  • enable - () => [string]: Used to connect the wallet. After a successful call, it will bring up the Bitget Wallet connection wallet page. Users can decide whether to connect the current DApp. If the user agrees, a single item array of the selected address will be returned.
  • on - (event, callback) => void: Add event listener
    • accountsChanged event: Triggered when the user switches accounts, returning an array of new addresses; when disconnected, an empty array is returned.
  • off - (event, callback) => void: Remove event listener
  • disconnect - Disconnect the wallet

Connect to Bitget Wallet

Parameters

  • options - object: Optional
    • starknetVersion - v4 | v5: Default is v5
js
const [public_address] = await provider.enable();
//const [public_address] = await provider.enable({ starknetVersion: 'v4' });

const account = provider.account;
// account = {
//     address: "0x04a6f...52f4d801c84",
//     cairoVersion: "0",
//     sdkVersion: "v5",
//     ...
// }

provider.on("accountsChanged", (event) => {
    // cb(event)...
});
const [public_address] = await provider.enable();
//const [public_address] = await provider.enable({ starknetVersion: 'v4' });

const account = provider.account;
// account = {
//     address: "0x04a6f...52f4d801c84",
//     cairoVersion: "0",
//     sdkVersion: "v5",
//     ...
// }

provider.on("accountsChanged", (event) => {
    // cb(event)...
});

Add Token

Parameters

  • type - string: wallet_watchAsset
  • params - object: Token information
js
const res = await provider.request({
    type: 'wallet_watchAsset',
    params: {
        type: 'ERC20',
        options: {
            address: '0x0A4E1BdFA75292A98C15870AeF24bd94BFFe0Bd4',
            symbol: 'FOTA',
            name: 'FOTA'
        }
    }
})
const res = await provider.request({
    type: 'wallet_watchAsset',
    params: {
        type: 'ERC20',
        options: {
            address: '0x0A4E1BdFA75292A98C15870AeF24bd94BFFe0Bd4',
            symbol: 'FOTA',
            name: 'FOTA'
        }
    }
})

Signature

Parameters

  • typedData - object: The object to be signed, refer to the EIP-712 standard

Return Value

  • signature - string[]: The result of the signature, containing two items
js
const typedData = {
    domain: {
        name: "Starknet demo app",
        version: "1",
        chainId: 'SN_MAIN',
    },
    types: {
        StarkNetDomain: [
        { name: "name", type: "felt" },
        { name: "version", type: "felt" },
        { name: "chainId", type: "felt" },
        ],
        Message: [{ name: "message", type: "felt" }],
    },
    message: {
        message: 'sign message test',
    },
    primaryType: "Message",
};
const [r, s] = await provider.signMessage(typedData);
const typedData = {
    domain: {
        name: "Starknet demo app",
        version: "1",
        chainId: 'SN_MAIN',
    },
    types: {
        StarkNetDomain: [
        { name: "name", type: "felt" },
        { name: "version", type: "felt" },
        { name: "chainId", type: "felt" },
        ],
        Message: [{ name: "message", type: "felt" }],
    },
    message: {
        message: 'sign message test',
    },
    primaryType: "Message",
};
const [r, s] = await provider.signMessage(typedData);

Contract Call

Execute one or more calls. If there is only one call, transactions is an object with properties described below. If there are multiple calls, it is an array of objects.

Parameters

  • transactions - object:
    • contractAddress - string: Contract address
    • entrypoint - string: Contract entry point
    • calldata - array: Call data
    • signature - array: Signature
  • abi - Contract ABI, optional

Return Value

  • result - object
    • transaction_hash - string: Transaction hash
js
// Using StarkGate: ETH Token as an example
const transactions = {
    contractAddress: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
    entrypoint: 'transfer',
    calldata: CallData.compile({
        recipient: '0x05b98d6ccbb660c3ca3c699f8dc0d2c8f58c539feac4fe2d57def7d2fa7312d1',
        amount: cairo.uint256(1000000000n)
    })
}
// "transactions": {
//     "contractAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
//     "entrypoint": "transfer",
//     "calldata": [
//         "2589407029262891725723779965976037245771646239489440786683818579381309346513",
//         "1000000000",
//         "0"
//     ]
// },
const res = await provider.execute(transactions);
// Using StarkGate: ETH Token as an example
const transactions = {
    contractAddress: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
    entrypoint: 'transfer',
    calldata: CallData.compile({
        recipient: '0x05b98d6ccbb660c3ca3c699f8dc0d2c8f58c539feac4fe2d57def7d2fa7312d1',
        amount: cairo.uint256(1000000000n)
    })
}
// "transactions": {
//     "contractAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
//     "entrypoint": "transfer",
//     "calldata": [
//         "2589407029262891725723779965976037245771646239489440786683818579381309346513",
//         "1000000000",
//         "0"
//     ]
// },
const res = await provider.execute(transactions);

For other properties and methods on starknet.account and starknet.provider, please refer to the starknet.js documentation.