Graphite Web3 Documentation

Basic Usage

  • Detect the provider (window.graphite)

  • Call the window.graphite.enable() method

  • If access is granted, use the available api

Available methods

graphite.enable(): Promise<bool>

Calling this method triggers a user interface that allows a user to approve or reject account access for a given dApp. This method returns a Promise that is resolved with an account if the user approves access or is rejected with an Error if the user rejects access.

await window.graphite.enable()
// If success:
// => 0xca8a66887dfbEf870a2d96de536986516a37fa12

// If regected:
// throw Error {
//  "code": -1,
//  "message": "User rejected the request."
//}

graphite.isEnabled(): Promise<bool>

Returns true if the dApp is already connected to a user's wallet, or if requesting access would return true without user confirmation (e.g. the dApp is whitelisted), and false otherwise.

await window.graphite.isEnabled()
// => true

graphite.request(): Promise<Object>

JSON-RPC request to interact with the Graphite node.

await window.graphite.request({
  "jsonrpc":"2.0",
  "method":"eth_getBalance",
  "params": ["0x1D9f2C01c8A20DcC59e806caFF5f46033e84ad2B", "latest"],
  "id":1
})
// => {
//    "jsonrpc": "2.0",
//    "id": 1,
//    "result": "0x6e9ce78211603c34113800"
// }

graphite.getBalance(): Promise<number>

JSON-RPC request to interact with the Graphite node.

const balance = await window.graphite.getBalance()
// balance => 1094658474000000000

graphite.getAddress(): Promise<string>

Returns the active account.

const account = await window.graphite.getAddress()
// account => '0xca8a66887dfbEf870a2d96de536986516a37fa12'

graphite.getAccountInfo(): Promise<object>

Returns basic account information, such as balance, activation status, KYC level and KYC filter.

const info = await window.graphite.getAccountInfo()
// info => {
//    "balance": "0xf31021515242400",
//    "active": true,
//    "kycLevel": "1",
//    "kycFilterLevel": "2"
//    "reputation": "255"
//  }

graphite.sendTx(params): Promise<string>

To send a transaction, use the sendTx method where params is a options object. The wallet should ask the user for permission, and if given, try to sign and send transactions. This returns the transaction hash, if the transaction was submitted successfully, otherwise throws an error.

const account = await window.graphite.getAddress()
const nonce = await window.graphite.request({
  "jsonrpc":"2.0",
  "method":"eth_getTransactionCount",
  "params": [account, "latest"],
  "id":1
})
const params = {
  nonce,
  from: account,
  to: '0x3526e99937B60E2CC18f10f6262B4D320FD2E371',
  value: '1000000000000',
  gasPrice: '18000000000',
  gas: '22000'
}
let hash = await window.graphite.sendTx(params)
// => '0x42d340b0e52ae61f0e004bd1939a3a8d23f02e6e09daf0ed402817948273e9ce'

graphite.activateAccount(): Promise<string>

To send transactions on Graphite, a user needs to activate their account. This can be done using the method activateAccount. The wallet should ask the user for permission to activate. This returns the transaction hash, if the transaction was submitted successfully, otherwise throws an error. The account balance must be non-zero.

const hash = window.graphite.activateAccount()
// => '0x42d340b0e52ae61f0e004bd1939a3a8d23f02e6e09daf0ed402817948273e9ce'

graphite.updateKycLevel(level): Promise<string>

To change the KYC level, use the method updateKycLevel. The wallet should ask the user for permission to change the level. Returns the transaction hash, if transaction was submitted successfully, otherwise throws an error. The account must already be activated and have a non-zero balance. The parameter level can be from 1 to 3.

const hash = window.graphite.updateKycLevel(1)
// => {
// hash: '0x42d340b0e52ae61f0e004bd1939a3a8d23f02e6e09daf0ed402817948273e9ce',
// uuid: 'd1c2b8a9-2976-4615-b7f4-2aca95a50123'
// }

graphite.updateKycFilter(filter): Promise<string>

To change the KYC filter, use the method updateKycFilter. The wallet should ask the user for permission to change the filter. Returns the transaction hash, if transaction was submitted successfully, otherwise throws an error. The account must already be activated and have a non-zero balance. The parameter filter can be from 1 to 3.

const hash = window.graphite.updateKycFilter(2)
// => '0x42d340b0e52ae61f0e004bd1939a3a8d23f02e6e09daf0ed402817948273e9ce'

graphite.getLastKycRequest(): Promise<Object>

Returns the latest KYC request data for the user based on the active network.

const lastKycRequest = await window.graphite.getLastKycRequest()
// lastKycRequest => {
//  "address":"0x9684055b99332231F34C27423a0A9d968dBC6379",
//  "lastKycTxHash":"0x42d340b0e52ae61f0e004bd1939a3a8d23f02e6e09daf0ed402817948273e9ce",
//  "centre": "0x8D8129f2F56D87F39a3dEA1ba33a3bd930849F81",
//  "deposite": "0",
//  "level": "1",
//  "status": "0",
//  "statusName": "pending",
//  "uuid": "d05875e9-c9b0-4312-a349-874f6ef317df"
// }

Events

graphite.onNetworkChange(network)

Returns the network id (1 or 0) when the network was changed.

window.graphite.onNetworkChange((network) => void)

Last updated