Skip to content

Commit

Permalink
add auth to glif requests (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber authored Jan 2, 2024
1 parent 75fe611 commit c87e4e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/ie-contract.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ethers } from 'ethers'
import { IE_CONTRACT_ABI, IE_CONTRACT_ADDRESS, RPC_URL } from '../spark-publish/ie-contract-config.js'
import { IE_CONTRACT_ABI, IE_CONTRACT_ADDRESS, RPC_URL, GLIF_TOKEN } from '../spark-publish/ie-contract-config.js'

const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const provider = new ethers.providers.JsonRpcProvider({
url: RPC_URL,
headers: {
Authorization: `Bearer ${GLIF_TOKEN}`
}
})

// Uncomment for troubleshooting
// provider.on('debug', d => console.log('[ethers:debug] %s\nrequest: %o\nresponse: %o', d.action, d.request, d.response))
Expand Down
14 changes: 12 additions & 2 deletions spark-publish/bin/publish-batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { ed25519 } from '@ucanto/principal'
import { CarReader } from '@ipld/car'
import { importDAG } from '@ucanto/core/delegation'
import { ethers } from 'ethers'
import { IE_CONTRACT_ABI, IE_CONTRACT_ADDRESS, RPC_URL } from '../ie-contract-config.js'
import {
IE_CONTRACT_ABI,
IE_CONTRACT_ADDRESS,
RPC_URL,
GLIF_TOKEN
} from '../ie-contract-config.js'
import assert from 'node:assert'
import { writeClient } from '../lib/telemetry.js'

Expand Down Expand Up @@ -49,7 +54,12 @@ const proof = await parseProof(W3UP_PROOF)
const space = await web3Storage.addSpace(proof)
await web3Storage.setCurrentSpace(space.did())

const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const provider = new ethers.providers.JsonRpcProvider({
url: RPC_URL,
headers: {
Authorization: `Bearer ${GLIF_TOKEN}`
}
})
const signer = ethers.Wallet.fromMnemonic(WALLET_SEED).connect(provider)
const ieContract = new ethers.Contract(
IE_CONTRACT_ADDRESS,
Expand Down
4 changes: 3 additions & 1 deletion spark-publish/ie-contract-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { fileURLToPath } from 'node:url'

const {
IE_CONTRACT_ADDRESS = '0xaaef78eaf86dcf34f275288752e892424dda9341',
RPC_URLS = 'https://api.node.glif.io/rpc/v0,https://api.chain.love/rpc/v1'
RPC_URLS = 'https://api.node.glif.io/rpc/v0,https://api.chain.love/rpc/v1',
GLIF_TOKEN
} = process.env

const rpcUrls = RPC_URLS.split(',')
Expand All @@ -20,6 +21,7 @@ const IE_CONTRACT_ABI = JSON.parse(
export {
IE_CONTRACT_ADDRESS,
RPC_URL,
GLIF_TOKEN,
rpcUrls,
IE_CONTRACT_ABI
}

0 comments on commit c87e4e1

Please sign in to comment.