Skip to content

Commit fee008a

Browse files
feat(transaction-builder): Add gas station support (#260)
* feat(transaction-builder): Add gas station support improve API Add example and fix gas station impl fix env path oops augh add env clippy and try with url try creating both env and an address I dunno move env creation flip try this reorder again say --yes logs fix sed bindings use jq raw try quotes rename debug use pipes get the keypair oop debug try another host tweaks try printing err try moving auth caps one more time oh 🤦‍♀️ try not waiting ffs 100 retries * tweak the github CI * rename token * error when out of retries * digest in err
1 parent 464ee10 commit fee008a

File tree

22 files changed

+1697
-148
lines changed

22 files changed

+1697
-148
lines changed

.github/actions/start-local-network/action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,26 @@ runs:
2121
echo "$(pwd)" >> $GITHUB_PATH
2222
./iota start --force-regenesis --with-faucet --with-indexer --with-graphql --pg-port 5432 --pg-db-name iota_indexer_v2 --epoch-duration-ms $EPOCH_DURATION_MS &
2323
sleep $((EPOCH_DURATION_MS / 1000)) # wait for the first epoch to end
24+
25+
- name: Start gas station and request faucet coins
26+
shell: bash
27+
env:
28+
GAS_STATION_AUTH: "test"
29+
run: |
30+
./iota client -y new-env --alias localnet --rpc http://127.0.0.1:9000 --graphql http://0.0.0.0:9125 --faucet http://127.0.0.1:9123/v1/gas
31+
./iota keytool update-alias $(./iota client active-address) gas_station
32+
33+
echo "Getting keypair"
34+
private_key="$(./iota keytool export gas_station --json | jq -r '.["exportedPrivateKey"]')"
35+
key="$(./iota keytool convert $private_key --json | jq -r '.["base64WithFlag"]')"
36+
37+
echo "Setting keypair in config"
38+
sed -i "s|<keypair>|$key|g" ./.github/actions/start-local-network/config.yaml
39+
40+
echo "Requesting faucet coins"
41+
./iota client faucet --address gas_station
42+
43+
echo "Starting Gas Station"
44+
docker compose -f ./.github/actions/start-local-network/gas_station_compose.yml up -d
45+
46+
docker logs iota-gas-station & sleep 10
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
signer-config:
3+
local:
4+
keypair: <keypair>
5+
rpc-host-ip: 0.0.0.0
6+
rpc-port: 9527
7+
metrics-port: 9185
8+
storage-config:
9+
redis:
10+
redis_url: "redis://localhost:6379"
11+
fullnode-url: "http://localhost:9000"
12+
coin-init-config:
13+
target-init-balance: 100000000
14+
refresh-interval-sec: 86400
15+
daily-gas-usage-cap: 1500000000000
16+
access-controller:
17+
access-policy: disabled
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Docker Compose configuration file for running the IOTA Gas Station in a container together with a Redis instance.
2+
# The intention of this docker-compose setup is to get up and running quickly in a development environment.
3+
# Please be aware that this setup is foundational and should be adjusted to your specific needs required for production.
4+
services:
5+
redis:
6+
image: redis:latest
7+
container_name: gas-station-redis
8+
volumes:
9+
- redis_data:/data
10+
network_mode: host
11+
iota-gas-station:
12+
image: "${DOCKER_IMAGE:-iotaledger/gas-station:latest}"
13+
build:
14+
context: ..
15+
args:
16+
- BUILD_DATE=${BUILD_DATE:-latest}
17+
- GIT_REVISION=${GIT_REVISION:-latest}
18+
dockerfile: docker/Dockerfile
19+
container_name: iota-gas-station
20+
command: ["--config-path", "/app/config.yaml"]
21+
depends_on:
22+
- redis
23+
ports:
24+
- "9527:9527" # RPC port
25+
- "9185:9185" # Metrics port
26+
environment:
27+
- CONFIG_PATH=/app/config.yaml
28+
- RUST_BACKTRACE=1
29+
- GAS_STATION_AUTH=${GAS_STATION_AUTH:-}
30+
volumes:
31+
- ${LOCAL_CONFIG_PATH:-./config.yaml}:/app/config.yaml
32+
network_mode: host
33+
34+
volumes:
35+
redis_data:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2025 IOTA Stiftung
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
sdk "bindings/iota_sdk_ffi"
8+
"fmt"
9+
"log"
10+
)
11+
12+
func main() {
13+
client := sdk.GraphQlClientNewLocalnet()
14+
gasStationUrl := "http://0.0.0.0:9527"
15+
gasStationAuthToken := "test"
16+
keypair := sdk.Ed25519PrivateKeyGenerate()
17+
sender := keypair.PublicKey().DeriveAddress()
18+
simpleKey := sdk.SimpleKeypairFromEd25519(keypair)
19+
20+
builder := sdk.TransactionBuilderInit(sender, client)
21+
22+
package_id, _ := sdk.AddressFromHex("0x1")
23+
module_name, _ := sdk.NewIdentifier("u64")
24+
function_name, _ := sdk.NewIdentifier("sqrt")
25+
26+
builder.MoveCall(
27+
package_id,
28+
module_name,
29+
function_name,
30+
[]*sdk.PtbArgument{sdk.PtbArgumentU64(64)},
31+
nil,
32+
nil,
33+
)
34+
35+
headers := make(map[string][]string)
36+
headers["Authorization"] = []string{fmt.Sprintf("Bearer %v", gasStationAuthToken)}
37+
38+
builder.GasStationSponsor(gasStationUrl, nil, &headers)
39+
40+
res, err := builder.Execute(simpleKey, true)
41+
if err.(*sdk.SdkFfiError) != nil {
42+
log.Fatalf("Failed to sponsor transaction: %v", err)
43+
}
44+
45+
if res != nil {
46+
log.Printf("%v", *res)
47+
}
48+
49+
fmt.Print("Sponsored transaction was successful!")
50+
}

0 commit comments

Comments
 (0)