Skip to content

Instantly share code, notes, and snippets.

@bh2smith
Created June 11, 2024 13:37
Show Gist options
  • Save bh2smith/0ed1dfb405e65277a148408c1442a229 to your computer and use it in GitHub Desktop.
Save bh2smith/0ed1dfb405e65277a148408c1442a229 to your computer and use it in GitHub Desktop.
Multichain Gas Relayer Manual Interactions

Based on the instructions in Near Docs Here: https://docs.near.org/build/chain-abstraction/multichain-gas-relayer/relayer-gas-example

and related to resolution of the following issue:

Mintbase/near-ca#64

  1. Registration / Storage Deposit:
near contract call-function as-transaction v2.nft.kagi.testnet \
  storage_deposit json-args {} \
  prepaid-gas '100.0 Tgas' \
  attached-deposit '1 NEAR' \
  sign-as neareth-dev.testnet \
  network-config testnet \
  sign-with-keychain send
  1. Mint NFT
near contract call-function as-transaction v2.nft.kagi.testnet \
  mint json-args {} \
  prepaid-gas '100.0 Tgas' \
  attached-deposit '0 NEAR' \
  sign-as neareth-dev.testnet \
  network-config testnet \
  sign-with-keychain send
  1. Approve the Gas Station for this Token
near contract call-function as-transaction v2.nft.kagi.testnet \
  ckt_approve_call json-args '{"token_id":"32","account_id":"canhazgas.testnet","msg":""}' \
  prepaid-gas '100.0 Tgas' \
  attached-deposit '1 yoctoNEAR' \
  sign-as neareth-dev.testnet \
  network-config testnet \
  sign-with-keychain send

APPARENTLY (according to their test suite) we are suposed to use ckt_approve_call instead:

  1. Get Paymasters
near contract call-function as-transaction canhazgas.testnet \
  get_paymasters json-args '{"chain_id": "97"}' \
  prepaid-gas '100.000 Tgas' \
  attached-deposit '0 NEAR' \
  sign-as neareth-dev.testnet \
  network-config testnet \
  sign-with-keychain send

Result looks like this: This can be called by anyone (not sure why its not a view method)

[
  {
    "foreign_address": "0x98c6C99176911AD4E7fc7413eDF09956B2D7F0F8",
    "minimum_available_balance": "99890799999948172000",
    "nonce": 27,
    "token_id": "1"
  }
]

You may need to manually set the nonce:

near contract call-function as-transaction canhazgas.testnet \
  set_paymaster_nonce json-args '{"chain_id": "97","token_id": "1","nonce": 0}' \
  prepaid-gas '100.000 TeraGas' \
  attached-deposit '0 NEAR'
  1. Create Transaction
near contract call-function as-transaction canhazgas.testnet \
  create_transaction json-args '{"transaction_rlp_hex":"ea6180847735940085174876e800825208947f01d9b227593e033bf8d6fc86e634d27aa8556882045780c0","use_paymaster":true, "token_id": "32"}' \
  prepaid-gas '100.0 Tgas' \
  attached-deposit '2.9 NEAR' \
  sign-as neareth-dev.testnet \
  network-config testnet \
  sign-with-keychain send
--- Result -------------------------
{
  "id": "29",
  "pending_signature_count": 2
}
------------------------------------

Sample Tx: https://testnet.nearblocks.io/txns/6ZvLW19LwEu3AUmnRJe8DaYYQeYtSWXmfZtWmdsEpk6M

  1. Sign Next

Using the ID from the previous result call the following twice:

near contract call-function as-transaction canhazgas.testnet \
  sign_next json-args '{"id":"29"}' \
  prepaid-gas '300.0 Tgas' \
  attached-deposit '0 NEAR' \
  sign-as neareth-dev.testnet \
  network-config testnet \
  sign-with-keychain send

The second will emit an event with two signed transactions:

EVENT_JSON:{
  "standard":"x-gas-station",
  "version":"0.1.0",
  "event":"transaction_sequence_signed",
  "data":{
    "id":"29",
    "foreign_chain_id":"97",
    "created_by_account_id":"neareth-dev.testnet",
    "signed_transactions":[
      "0x02f872611b847735940085174876e800825208943dbdff087be3e6ff4eac2ed5662249fa13c36747870eebe0b40e800080c080a0b5a46fddf2250d8470e5c7d0bd2193b0461f3567f75132086fa04f7040f28476a04579a75b3ba4a9b0d4c13bcd6520b53029cb3be45b7d81a27de6d1039bc4f4ac",
      "0x02f86d6180847735940085174876e800825208947f01d9b227593e033bf8d6fc86e634d27aa8556882045780c001a0097dad4c458fc333b589e45f39104ca2f21398fda6a408e0a9fc33d3555b6702a070a35bda472801caea7e4f272e7073f6bcabc8e4475cc83be9037447b87009e0"
    ]
  }
}

They can be decoded here: https://rawtxdecode.in/

and broadcast to the appropriate network here:

#!/bin/bash

BSC_URL=https://data-seed-prebsc-1-s1.binance.org:8545

TX_A=0x02f872611b847735940085174876e800825208943dbdff087be3e6ff4eac2ed5662249fa13c36747870eebe0b40e800080c080a0b5a46fddf2250d8470e5c7d0bd2193b0461f3567f75132086fa04f7040f28476a04579a75b3ba4a9b0d4c13bcd6520b53029cb3be45b7d81a27de6d1039bc4f4ac

TX_B=0x02f86d6180847735940085174876e800825208947f01d9b227593e033bf8d6fc86e634d27aa8556882045780c001a0097dad4c458fc333b589e45f39104ca2f21398fda6a408e0a9fc33d3555b6702a070a35bda472801caea7e4f272e7073f6bcabc8e4475cc83be9037447b87009e0

# Send the raw transaction using cURL
RESPONSE_A=$(curl -s -X POST \
  -H "Content-Type: application/json" \
  --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"${TX_A}\"],\"id\":1}" \
  ${BSC_URL})

echo "Response: ${RESPONSE_A}"

Check the block exporer for the first to be mined and then run for TX_B:

You can also run it yourself as

curl -s -X POST \
  -H "Content-Type: application/json" \
  --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"${TX_A}\"],\"id\":1}" \
  ${BSC_URL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment