On-Chain Integration

Your on-chain smart contract has to check for a valid Civic Pass during program execution and reject transactions from non-compliant users (i.e. those without an active Civic Pass).

For each blockchain supported by Civic Pass, we provide you with a library that is tailored to the programming model of that chain.

Import the solana_gateway Rust crate from crates.io as follows:

[dependencies]
solana-gateway = { version = "0.4.0", features = ["no-entrypoint"] }

In your instruction code, call: Gateway::verify_gateway_token_account_info

For your program to be able to call the integration library, the following parameters must be passed as inputs to your dApp's transaction:

  • userWallet : The wallet account for the dApp user. A Civic Pass must have already been issued to this wallet.

  • gateway_token : The address of the Civic Pass. This address can be accessed in the dApp through the useGateway hook on the Civic React Component once the user has passed verification.

  • gatekeeper_network : The Gatekeeper Network on which the Civic Pass has been issued.

See Gatekeeper Networks for the list of available networks.

use solana_gateway::Gateway;

// This check happens before the dApp transaction is processed
fn process() -> ProgramResult {
    // The owner of the gateway token
    let user_wallet: AccountInfo;
    // The gateway token presented by the owner
    let gateway_token: AccountInfo;
    // The gatekeeper network key
    let gatekeeper_network: Pubkey;
    
    // Check the token is valid. An error here means the token 
    // is not valid for the user's wallet on the gateway network.
    Gateway::verify_gateway_token_account_info(
        &gateway_token_account_info, &userWallet.key, &gatekeeper
    )?;
    
    Ok(())
}

Error handling

If something goes wrong or the token it invalid, the Gateway call will return a GatewayError. The possible values can be seen in error.rs. For error cases, the dApp smart contract should reject the transaction.

Last updated