✅오늘은 뭐했나?
- ethers.js (설정, 기본 기능 및 거래 보내기)
npm install --save ethers
node
var {ethers} = require('ethers')
var provider_main = new ethers.InfuraProvider()
var provider_goerli = new ethers.InfuraProvider(network="goerli")
await provider_main.getBlockNumber()
await provider_goerli.getBlockNumber()
await provider_goerli.getBalance('지갑주소')
await provider.getBlockNumber()
npm install --save ethers
node
var { ethers } = require("ethers");
var provider = new ethers.InfuraProvider(network="goerli", "api key")
var privateKey = '개인키'
var signer = new ethers.Wallet(privateKey, provider)
var tx = {to : account2, value : 100000000}
var Txreceipt = signer.sendTransaction(tx).then(console.log)
- ethers.js (getCode, getStorageAt() // contract의 바이트 코드와 상태변수)
pragma solidity ^0.8.18;
contract A {
uint public a = 1;
uint public b = 2;
uint public c = 3;
function setA(uint _a) public {
a = _a;
}
function setB(uint _b) public {
b = _b;
}
function setC(uint _c) public {
c = _c;
}
}
await provider_goerli.getCode('contract 주소')
await provider_goerli.getStorageAt('contract 주소', '번호')
await provider_goerli.getStorage('contract 주소', '0')
await provider_goerli.getStorage('contract 주소', '1')
await provider_goerli.getStorage('contract 주소', '2')
- ethers.js (contract 사용하기)
var { ethers } = require("ethers");
var provider = new ethers.InfuraProvider(network="goerli", "api key")
var privateKey = '개인키'
var signer = new ethers.Wallet(privateKey, provider)
var abi = abi넣기
var c_address = contract address 넣기
contract.interface.fragments
await contract.a()
var txSigner = contract.connect(signer)
contract Origin {
function A() public view returns(uint, address) {
return (1, msg.sender);
}
function B() public view returns(uint, address) {
return (2, address(this));
}
function C() public view returns(uint, address) {
return (3, tx.origin);
}
}
contract Sub {
Origin a;
constructor(address _a) {
a = Origin(_a);
}
function A() public view returns(uint, address) {
return a.A();
}
function B() public view returns(uint, address) {
return a.B();
}
function C() public view returns(uint, address) {
return a.C();
}
}
pragma solidity >=0.8.2 <0.9.0;
contract multiArray {
uint[][] public double_A;
function setNumber(uint _a) public {
double_A.push([_a]);
}
function setNumber2(uint _a, uint _b) public {
double_A.push([_a, _b]);
}
function setNumber3(uint[] memory _a) public {
double_A.push(_a);
}
function setNumber4(uint _a, uint _b, uint _c) public {
double_A[_a][_b] = _c;
}
function getLength() public view returns(uint) {
return double_A.length;
}
function getLength2(uint _a) public view returns(uint) {
return double_A[_a].length;
}
}
contract multiArray2 {
uint[3][] public double_A;
function setNumberA(uint _a) public {
double_A.push([_a]);
}
function setNumberA2(uint _a, uint _b) public {
double_A.push([_a, _b]);
}
function setNumberA3(uint[3] memory _a) public {
double_A.push(_a);
}
function setNumberA4(uint _a, uint _b, uint _c) public {
double_A[_a][_b] = _c;
}
function getLengthA() public view returns(uint) {
return double_A.length;
}
function getLengthA2(uint _a) public view returns(uint) {
return double_A[_a].length;
}
}
contract multiArray2_2 {
uint length;
uint[][] public double_A = new uint[3][](length);
function setNumberA(uint _a) public {
double_A.push([_a]);
}
function setNumberA2(uint _a, uint _b) public {
double_A.push([_a, _b]);
}
function setNumberA3(uint[3] memory _a) public {
double_A.push(_a);
}
function setNumberA4(uint _a, uint _b, uint _c) public {
double_A[_a][_b] = _c;
}
function getLengthA() public view returns(uint) {
return double_A.length;
}
function getLengthA2(uint _a) public view returns(uint) {
return double_A[_a].length;
}
}
contract multiArray3 {
uint[][3] public double_A;
function setNumberA(uint _a, uint _b, uint _c) public {
double_A[_a][_b] = _c;
}
function setNumberA2(uint _a, uint[] memory _b) public {
double_A[_a] = _b;
}
function getLengthA() public view returns(uint) {
return double_A.length;
}
function getLengthA2(uint _a) public view returns(uint) {
return double_A[_a].length;
}
}
contract multiArray3_2 {
uint[][] public double_A = new uint[][](3);
function setNumberA(uint _a, uint _b, uint _c) public {
double_A[_a][_b] = _c;
}
function setNumberA2(uint _a, uint[] memory _b) public {
double_A[_a] = _b;
}
function getLengthA() public view returns(uint) {
return double_A.length;
}
function getLengthA2(uint _a) public view returns(uint) {
return double_A[_a].length;
}
}
contract multiArray4 {
uint[3][3] public double_A;
function setNumberA(uint _a, uint _b, uint _c) public {
double_A[_a][_b] = _c;
}
function setNumberA2(uint _a, uint[3] memory _b) public {
double_A[_a] = _b;
}
function getLengthA() public view returns(uint) {
return double_A.length;
}
function getLengthA2(uint _a) public view returns(uint) {
return double_A[_a].length;
}
}
contract gasFee {
uint[] a;
uint[][] a_;
uint[3][] _a;
uint[3] b;
uint[][3] b_;
uint[3][3] _b;
function setA(uint _a) public {
a.push(_a);
}
function setA2(uint _a) public {
a_.push([_a]);
}
function setA3(uint _b) public {
_a.push([_b]);
}
function setA3_(uint[3] memory _b) public {
_a.push(_b);
}
function setB(uint _n, uint _a) public {
b[_n] = (_a);
}
function setB2(uint _n, uint _a) public {
b_[_n] = [_a];
}
function setB3(uint _a, uint _bb, uint _c) public {
_b[_a][_bb] = _c;
}
}