Public
Edited
Oct 13, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
wallet = ethers.Wallet.createRandom()
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
provider = new ethers.providers.JsonRpcProvider(`${baseUrl}/rpc/v0?token=${token}`)
Insert cell
deployer = new ethers.Wallet(ownerKey.privateKey, provider)
Insert cell
deployer.address
Insert cell
deployer.privateKey
Insert cell
factory = new ethers.ContractFactory(iface, contractBytes, deployer)
Insert cell
nonce = client.mpoolGetNonce(ownerKey.f1Address)
Insert cell
viewof devCreateActorButton = Inputs.button(
'Create EVM Actor (Dev)',
{
disabled: !ready,
value: null,
reduce: () => client.mpoolGetNonce(ownerKey.f1Address)
}
)
Insert cell
devCreateActorButton
Insert cell
priorityFee = client.callEthMethod('maxPriorityFeePerGas')
Insert cell
unsignedTx = devCreateActorButton && factory.getDeployTransaction(
constructorParamsForm[0], // name - string
constructorParamsForm[1], // symbol - string
constructorParamsForm[2], // initialSupply - uint256
deployer.address,
{
gasLimit: 1000000000,
gasPrice: undefined,
maxFeePerGas: undefined,
maxPriorityFeePerGas: priorityFee,
value: undefined,
nonce: devCreateActorButton
}
)
Insert cell
populatedTx = {
if (!unsignedTx) return
const tx = {...unsignedTx}
console.log('Transaction', tx)
//return deployer.sendTransaction(tx)
return deployer.populateTransaction(tx)
}
Insert cell
signedTx = deployer.signTransaction(populatedTx)
Insert cell
provider.formatter.transaction(signedTx)
Insert cell
// deployer.sendTransaction(populatedTx)
Insert cell
deployTransaction = client.callEthMethod('sendRawTransaction', [signedTx])
Insert cell
deployTransactionResults = client.callEthMethod('getTransactionReceipt', [deployTransaction])
Insert cell
/* contract = await factory.deploy(
constructorParamsForm[0], // name - string
constructorParamsForm[1], // symbol - string
constructorParamsForm[2], // initialSupply - uint256
deployer.address
)
*/
Insert cell
client.chainHead()
Insert cell
chainId = client.callEthMethod('chainId')
Insert cell
createActorStatus = {
return
if (createActorButton) {
console.log('Create actor')
const start = Date.now()
yield {
creating: true,
start
}
// Needs a zero byte in front
const evmActorCidBytes = new Uint8Array(evmActorCid.bytes.length + 1)
evmActorCidBytes.set(evmActorCid.bytes, 1)
const params = cbor.encode([new cbor.Tagged(42, evmActorCidBytes), evmBytesCbor])
// Sending create actor message...
const messageBody = {
To: 't01',
From: walletDefaultAddress,
Value: "0",
Method: 2,
Params: params.toString('base64')
}
console.log('messageBody', messageBody)
const response = await client.mpoolPushMessage(messageBody, null)
const waitStart = Date.now()
yield { waiting: true, waitStart, response }
const waitResponse = await client.stateWaitMsg(response.CID, 0)
yield { installed: true, response, waitResponse }
}
}
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
client
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
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
filecoinAddress = import('https://cdn.skypack.dev/@glif/filecoin-address')
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
Insert cell
client = {
const provider = new BrowserProvider(`${baseUrl}/rpc/v0`, { token })
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}/rpc/v0`, token)
Insert cell
lotusApiClient = {
const connector = new filecoinJs.HttpJsonRpcConnector({ url: baseUrl, token })
return new filecoinJs.LotusClient(connector)
}
Insert cell
async function *heightStream () {
let last
while (true) {
try {
const newHeight = (await client.chainHead()).Height
if (newHeight !== last) {
yield newHeight
last = newHeight
}
} catch (e) {
yield 0
}
await Promises.delay(4000)
}
}
Insert cell
mutable ready = false
Insert cell
async function *heightReadyTapStream () {
let lastReady = false
for await (const height of heightStream()) {
const newReady = height > 7
if (newReady !== lastReady) {
mutable ready = newReady
lastReady = newReady
}
yield height
}
}
Insert cell
currentHeight = heightReadyTapStream()
Insert cell
walletDefaultAddress = ready && client.walletDefaultAddress()
Insert cell
function getEvmAddress (address) {
return '000000000000000000000000ff' + Number(address.slice(1)).toString(16).padStart(38, '0')
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more