Skip to content

Instantly share code, notes, and snippets.

fuji: {
url: 'https://api.avax-test.network/ext/bc/C/rpc',
gasPrice: 225000000000,
chainId: 43113,
accounts: [
"0x7727b8bf7f114f93cede28f67da7ac4fbcd34d481f4bb1597256102985ebea17", //private key
"0x40c933e2b79efc76286ad0190d64eeg43dd6724a4b2674bb2f83ac63c2aabe19",
"0x1637e4c222057f9d3b177d7a5dd1aba62baf9ebe0fa511cb2944b0e70b062a68",
"0x5a4758ffb1216ab80ce6c6fa374833f1f10f1966ca9ff7fa13332e4bd78d43c7",
"0x4d4849a8d599a6adc9d58a3b76fcf90dcedea99fed5a425dc4f4a55f120ce8e8",
const avalanche = require("avalanche");
let bintools = avalanche.BinTools.getInstance();
const ID = 1;
const ava = new avalanche.Avalanche("api.avax-test.network", 443, "https", networkID);
const xchain = ava.XChain();
let xKeychain = xchain.keyChain();
let keypair = xKeychain.makeKey();
//p ublic and private keys
let pubkstr = keypair.getPublicKeyString();
<script>
import {get} from "svelte/store";
export const getBalance = (contract) => async (e) => {
await contract; // ensure $web3.eth is defined
return get(web3).eth.getBalance(get(selectedAccount));
};
export let checkAccount = get(selectedAccount) || "0x0000000000000000000000000000000000000000";
let myContract = getContext("myContract");
</script>
export const transfer= (contract) => (to) => async (tokenId) => {
let myContract = await contract;
try {
let tx = await get(web3).eth.sendTransaction({
gasPrice: get(web3).utils.toHex(get(web3).utils.toWei("225", "gwei")),
gasLimit: get(web3).utils.toHex("600000"),
from: get(selectedAccount),
to: contractAddress,
data: myContract.methods.transfer(to, tokenId).encodeABI(),
});
import {web3, selectedAccount, chainId, connected} from "svelte-web3";
import {contractAddress, abi} from "./utils/contract.js";
let myContract;
let init = async () => {
await ethStore.setProvider("https://api.avax-test.network/ext/bc/C/rpc");
await ethStore.setBrowserProvider();
let contract = await new $web3.eth.Contract(abi, contractAddress);
if ($chainId != 43113) {
alert("Warning: You are not connected to Avalanche Fuji test-net!");
}
@apow2
apow2 / axios.js
Last active June 27, 2023 06:20
use axios to get data from IPFS
import axios from "axios";
let myContract;
let init = async () => {
await ethStore.setProvider("https://api.avax-test.network/ext/bc/C/rpc");
await ethStore.setBrowserProvider();
let contract = await new $web3.eth.Contract(abi, contractAddress);
if ($chainId != 43113) {
alert("Warning: You are not connected to Avalanche Fuji test-net!");
}
@apow2
apow2 / pinata_ipfs.js
Last active April 30, 2021 01:41
pin to ipfs
const pinataSDK = require('@pinata/sdk');
const pinata = pinataSDK(yourKey, yourKey2);
const fs = require('fs');
function getStream(){
return fs.createReadStream(PATH_TO_IMAGES+files[i]);
}
let readableStreamForFile = getStream();
//pin on IPFS
cur_promise = await new Promise((resolve, reject) => {
const tx = {
from: address,
to: contractAddress,
gas: 20000,
value: 1000,
data: myContract.methods.setAddresses(MetaDataAddress, BINAddress).encodeABI(),
common: {customChain: {networkId:1, chainId: 43113}} //chain information
};
@apow2
apow2 / sink.sol
Created April 30, 2021 01:00
sink
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;
// This contract keeps all Ether sent to it with no way
// to get it back.
contract Sink {
event Received(address, uint);
receive() external payable {
emit Received(msg.sender, msg.value);
}
@apow2
apow2 / tipjar.sol
Last active April 30, 2021 01:00
a tip jar
contract TipJar{
address owner;
constructor() public{
owner = msg.sender;
}
receive() external payable{
}
fallback() external payable {