Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bako Gateway documentation #10

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add deploy rust example
luisburigo committed Aug 23, 2024
commit b887ffc5a1c5f7dad488a81f7d06c0904c0c1e31
3 changes: 2 additions & 1 deletion pages/gateway/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"overview": "Overview",
"quick-start": "Quickstart"
"quick-start": "Quickstart",
"examples": "Examples"
}
65 changes: 65 additions & 0 deletions pages/gateway/examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### Rust example

1. Setup the URL and API Token:

```rust
const API_TOKEN: &str = "";
const BAKO_GATEWAY_URL: &str = "https://api.bako.global/v1/graphql?api_token=";
```

2. Connect in our GraphQL Gateway:

```rust
let node_url = format!("{BAKO_GATEWAY_URL}{API_TOKEN}");
let client = FuelClient::new(node_url.clone()).expect("Failed to create FuelClient");
let provider = Provider::connect(node_url)
.await
.expect("Failed to connect to provider");
```

3. Load the contract:

```rust
let contract = Contract::load_from(
"../contracts/contract/out/release/contract.bin",
LoadConfiguration::default(),
)
.expect("Failed to load contract");
```

4. Prepare the transaction for contract deployment

```rust
let contract_id = contract.contract_id();
let state_root = contract.state_root();
let salt = contract.salt();
let storage_slots = contract.storage_slots();
let code = contract.code();

let transaction_builder = CreateTransactionBuilder::prepare_contract_deployment(
code,
contract_id,
state_root,
salt,
storage_slots.to_vec(),
Default::default(),
)
.with_max_fee_estimation_tolerance(0.05);

let transaction = transaction_builder
.build(provider.clone())
.await
.expect("Failed to build transaction");
let tx = Transaction::from(transaction);
```

5. Submit the transaction to the Gateway:

```rust
let tx_id = client
.submit(&tx)
.await
.expect("Failed to submit transaction");
```

[See in context]()
Loading