Skip to content

Instantly share code, notes, and snippets.

@dabit3
Last active February 14, 2023 03:51
Show Gist options
  • Save dabit3/b9260e81e6269dd6772d0a127333426c to your computer and use it in GitHub Desktop.
Save dabit3/b9260e81e6269dd6772d0a127333426c to your computer and use it in GitHub Desktop.
Arweave client example with Matic
import { WebBundlr } from "@bundlr-network/client"
import { providers } from "ethers"
/* initialize some local state to store the bundlr instance */
const [bundlrInstance, setBundlrInstance] = useState(null)
/* connect to the user's wallet */
async function connect() {
await window.ethereum.request({ method: 'eth_requestAccounts' })
const provider = new providers.Web3Provider(window.ethereum)
await provider._ready()
const bundlr = new WebBundlr("https://node1.bundlr.network", "matic", provider)
await bundlr.ready()
setBundlrInstance(bundlr)
}
/* create a transaction (plain text, JSON, file, image, video, etc..) */
async function createTransaction() {
const data = "hello world"
const tags = [{name: "Content-Type", value: "text/plain"}]
const transaction = bundlrInstance.createTransaction(data, { tags })
await transaction.sign()
await transaction.upload()
console.log('transaction id: ', transaction.id)
}
/*
** Now your content can be instantly accessed via https://arweave.net/[id]
**
** Supported currencies:
** Arweave (AR)
** Solana (SOL)
** Polygon (MATIC)
** Ethereum (ETH)
** Binance Smart Chain (BNB)
** Avalanche C-Chain (AVAX)
** Boba (ETH)
** Chainlink (CHAIN)
** Arbitrum (ETH)
** Optimism (ETH)
** Fantom (FANTOM)
** NEAR (NEAR)
** Algorand (ALGO)
*/
@EidSubaie
Copy link

Incomplete code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment