Public
Edited
Jan 30, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ownerKey.privateKey
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
skypack = (library) => import(`https://cdn.skypack.dev/${library}?min`)
Insert cell
LotusRPC = (await import('@filecoin-shipyard/lotus-client-rpc')).LotusRPC
Insert cell
BrowserProvider = (await import('@filecoin-shipyard/lotus-client-provider-browser')).BrowserProvider
Insert cell
schema = (await import('@filecoin-shipyard/lotus-client-schema')).mainnet.fullNode
Insert cell
stripAnsi = (await import('https://unpkg.com/strip-ansi@7.0.1/index.js?module')).default
Insert cell
cbor = import('https://cdn.skypack.dev/borc')
Insert cell
multiformats = import('https://cdn.skypack.dev/pin/multiformats@v9.6.5-93rn6JH3zqEZdoz77NBu/mode=imports,min/optimized/multiformats.js')
Insert cell
import {button} from '@jimpick/download-data-button-with-wasm-support'
Insert cell
buffer = require('https://bundle.run/buffer@6.0.3')
Insert cell
// filecoinJsSigner = import('https://jspm.dev/@blitslabs/filecoin-js-signer')
Insert cell
filecoinJs = (await import('https://jspm.dev/filecoin.js')).default
Insert cell
bip39 = require('https://bundle.run/bip39@3.0.4')
Insert cell
// FilecoinClient = filecoinJsSigner.FilecoinClient
Insert cell
// FilecoinSigner = filecoinJsSigner.FilecoinSigner
Insert cell
// filecoin_signer = new FilecoinSigner()
Insert cell
filecoinNumber = import('https://cdn.skypack.dev/pin/@glif/filecoin-number@v2.0.0-beta.0-iQnBkhznGjB3HsyiyYB8/mode=imports,min/optimized/@glif/filecoin-number.js')
Insert cell
FilecoinNumber = filecoinNumber.FilecoinNumber
Insert cell
ethers = import('https://cdn.skypack.dev/ethers@5.7.1?min')
Insert cell
provider = new ethers.providers.JsonRpcProvider(`${baseUrl}/rpc/v0?token=${token}`)
Insert cell
import {localStorage} from "@mbostock/safe-local-storage"
Insert cell
filecoinAddress = import('https://cdn.skypack.dev/@glif/filecoin-address')
Insert cell
buffer.Buffer.from(filecoinAddress.newFromString('t01000').bytes).toString('hex')
Insert cell
Insert cell
simpleCoinSol = `
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.25 <= 0.8.17;

contract SimpleCoin {
mapping (address => uint) balances;

event Transfer(address indexed _from, address indexed _to, uint256 _value);

constructor() {
balances[tx.origin] = 10000;
}

function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
if (balances[msg.sender] < amount) return false;
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Transfer(msg.sender, receiver, amount);
return true;
}

function getBalanceInEth(address addr) public view returns(uint){
return getBalance(addr) * 2;
}

function getBalance(address addr) public view returns(uint) {
return balances[addr];
}
}
`.trim()
Insert cell
Insert cell
Insert cell
token = ''
Insert cell
client = {
const provider = new BrowserProvider(`${baseUrl}/rpc/v0?token=`, {
sendHttpContentType: 'application/json'
})
// Monkey-patch in a method to call eth_* JSON-RPC methods
LotusRPC.prototype.callEthMethod = async function (method, args) {
await this.provider.connect()
const request = {
method: `eth_${method}`
}
request.params = args || []
return this.provider.send(request, {})
}
return new LotusRPC(provider, { schema })
}
Insert cell
filecoin_client = new FilecoinClient(baseUrl, token)
Insert cell
lotusApiClient = {
const connector = new filecoinJs.HttpJsonRpcConnector({ url: baseUrl, token })
return new filecoinJs.LotusClient(connector)
}
Insert cell
walletDefaultAddress = devFundsReady && devFundsAddress
Insert cell
function getEvmAddress (address) {
return '000000000000000000000000ff' + Number(address.slice(1)).toString(16).padStart(38, '0')
}
Insert cell
async function waitMsg (cid) {
// console.log('Waiting for', cid)
let waitResponse
for (let i = 0; i < 36; i++) { // 36 attempts at 5s each
waitResponse = await lotusApiClient.state.searchMsg(cid)
if (!waitResponse) {
// console.log('Sleeping 5s - ', cid['/'], i)
await Promises.delay(5000)
continue
}
}
return waitResponse
}
Insert cell
async function waitEthTx (txId) {
console.log('Waiting for', txId)
let waitResponse
for (let i = 0; i < 36; i++) { // 36 attempts at 5s each
try {
waitResponse = await client.callEthMethod('getTransactionReceipt', [txId])
} catch (e) {
if (e.message !== 'msg does not exist') {
console.log('Get transaction error', txId, e)
throw (e)
}
}
if (!waitResponse) {
console.log('Sleeping 5s - ', txId, i)
await Promises.delay(5000)
continue
}
}
return waitResponse
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more