I'm trying to implement Aave flash loan receiver in Vyper https://developers.aave.com/#implementing-a-flashloanreceiver-contract and I need to pass it an array of addresses as 'bytes memory _params' arg. Any ideas how do I encode an array of addresses to bytes in web3 and then decode them back from bytes to address[n] array in Vyper?
not sure what development environment you've opted with but Ethereum's Brownie has an Aave Flash-Loan template
if you already use brownie, to skip to the FLASH LOAN TEMPLATE section
otherwise, to install brownie there are a few requirements
check to see that you have node.js and npm already installed:
node -v
npm -v
if not run:
npm install -g npm
next install ganache-cli:
npm install -g ganache-cli
ganache-cli --version
if you don't have it already, install the latest python, then install pipx:
python -m pip install --user pipx
python -m pipx ensurepath
now install brownie:
pipx install eth-brownie
FLASH LOAN TEMPLATE:
check to make sure brownie is there, open a terminal and type:
brownie
to create a new project in brownie simply create a new directory to work in:
mkdir new_dir
cd new_dir
once in the new directory use the brownie key-word bake to create one of the templates available, see full list and instantiation instructions for each template at https://github.com/brownie-mix:
brownie bake aave-flashloan
and voila, you have a nice pre-made template and clear instructions for making it your own
if you want more info on brownie and testing with the brownie framework, i highly recommend reading Ben Hauser's many medium posts on the subject, he created the brownie framework and its pretty amazing, he can be found here https://iamdefinitelyahuman.medium.com/
addrBytes: Bytes[128] = concat(convert(32, bytes32), convert(2, bytes32), convert(addr0, bytes32), convert(addr1, bytes32))
funcsig: Bytes[4] = method_id("methodName(address[])")
full_data:Bytes[132] = concat(funcsig, addrBytes)
response: Bytes[128] = raw_call(contract_address, full_data, max_outsize=128)
result_address0: address = convert(slice(response, 64, 32), address)
result_address1: address = convert(slice(response, 96, 32), address)
This is the example if you want to pass a 2-length address array.
And I attach the reference to how you can encode dynamic arguments.
https://docs.soliditylang.org/en/v0.8.3/abi-spec.html#use-of-dynamic-types
Solidity and Vyper are the same in encoding arguments.
Related
I like to run a number of local tests. Everything works well on rinkeby and other test chains. However, the local development chain disagrees with my configuration.
When I run a forked development network:
brownie console --network mainnet-fork
The ganache-cli initiates as expected:
Brownie v1.18.1 - Python development framework for Ethereum
BlockchainProject is the active project.
Launching 'ganache-cli --accounts 10 --hardfork istanbul --fork https://mainnet.infura.io/v3/6a633a4ecae8449abbc69974cdd3a9b9 --gasLimit 12000000 --mnemonic brownie --port 8545 --chainId 1'...
Brownie environment is ready.
However, even the most simple contract interaction fails:
>>> link_token = Contract.from_explorer("0x514910771AF9Ca656af840dff83E8264EcF986CA")
Fetching source of 0x514910771AF9Ca656af840dff83E8264EcF986CA from api.etherscan.io...
>>> accounts[0].balance()
100000000000000000000
>>> accounts[1].balance()
100000000000000000000
>>> link_token.transfer(accounts[0].address, 100, {'from': accounts[0].address})
Transaction sent: 0x1542b679e4d09b2f4523427c7f5048ed01ee0d194c34cd27b82bbd177e1b3f23
Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 2
LinkToken.transfer confirmed (invalid opcode) Block: 14604608 Gas used: 12000000 (100.00%)
<Transaction '0x1542b679e4d09b2f4523427c7f5048ed01ee0d194c34cd27b82bbd177e1b3f23'>
Since the Link token is compiled with an unsupported compiler I do not get any further information on why this results in LinkToken.transfer confirmed (invalid opcode).
How do I (correctly) run chainlink code against a forked development network using brownie - am I missing a step such as funding??
My networks: configuration in brownie-config.yaml:
networks:
mainnet-fork:
vrf_coordinator: '0xf0d54349aDdcf704F77AE15b96510dEA15cb7952'
link_token: '0x514910771AF9Ca656af840dff83E8264EcF986CA'
keyhash: '0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445'
I did try to rm -rf build but that does not change anything.
System environment:
Brownie v1.18.1
Node 8.5.5
Ganache v7.0.4
21.3.0 Darwin Kernel Version (macOS 12.2.1)
Python 3.9.7
In this instance, the account used for Link token funding does not have any Link. For some reason, the transaction does not get reverted but the unlock: option of brownie provides assistance.
First adjusting the networks:settings to include an arbitrary account with a large Link balance:
mainnet-fork:
cmd_settings:
unlock:
- 0xf37c348b7d19b17b29cd5cfa64cfa48e2d6eb8db
vrf_coordinator: '0xf0d54349aDdcf704F77AE15b96510dEA15cb7952'
link_token: '0x514910771AF9Ca656af840dff83E8264EcF986CA'
keyhash: '0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445'
Second, run a mainnet-fork as before:
brownie console --network mainnet-fork
Third, confirm that the unlocked account is available and funded:
>>> accounts[10]
<Account '0xF37C348B7d19b17B29CD5CfA64cfA48E2d6eb8Db'>
>>> accounts[10].balance()
426496436000000000
Fourth, instantiate the contract of the token, Link in this instance:
link_token = Contract.from_explorer("0x514910771AF9Ca656af840dff83E8264EcF986CA")
Finally, transfer Link from the unlocked account to some other account (or contract):
link_token.transfer(accounts[0], 20, {"from": accounts[10]})
Alternatively, funding the mainnet address with Link, or even unlocking the Link owner and minting new Link would work too...
I have created and compiled a smart contract and created my deploy token file as well. When I run ganache-cli on one terminal it gives me '''eth_getTransactionByHash''' and while the brownie run scripts is running on the other terminal it says '''awaiting transaction from mempool'''
I logged into my MetaMask account as well and created a new Account with the RPC and chain ID provided.
Please help.
I had the same issue when running ganache-cli. I fixed it by passing some parameters
ganache-cli --port 8545 --gasLimit 12000000 --accounts 10 --hardfork istanbul --mnemonic brownie
I am setting up a Hyperledger Sawtooth network. In /etc/sawtooth/validator.toml.example, I saw the following:
# A Curve ZMQ key pair are used to create a secured network based on side-band
# sharing of a single network key pair to all participating nodes.
# Note if the config file does not exist or these are not set, the network
# will default to being insecure.
network_public_key = 'wFMwoOt>yFqI/ek.G[tfMMILHWw#vXB[Sv}>l>i)'
network_private_key = 'r&oJ5aQDj4+V]p2:Lz70Eu0x#m%IwzBdP(}&hWM*'
Can anybody tell me how to create another keypair?
These are the ZMQ message keys used to securely communicate with other nodes.
If you've installed sawtooth already, python3 and python3-zmq would have been already installed and available in your system. Here's an example to create the keypair in Python:
import zmq
(public, secret) = zmq.curve_keypair()
print("network_public_key =", public.decode("utf-8"),
"\nnetwork_private_key =", secret.decode("utf-8"))
Also, if you can use a compiled binary tool:
$ sudo apt-get install g++ libzmq3-dev
$ wget https://raw.githubusercontent.com/zeromq/libzmq/master/tools/curve_keygen.cpp
$ g++ curve_keygen.cpp -o curve_keygen -lzmq
$ ./curve_keygen
Copy the corresponding public key output to network_public_key and the private key output to network_private_key fields in /etc/sawtooth/validator.toml
The above was from my Sawtooth FAQ at
https://sawtooth.hyperledger.org/faq/validator/#how-do-i-generate-the-network-public-key-and-network-private-key-in-validator-toml
I'm using Electric as design system. I want to simulate in LTSPICE the designed circuit.
I've linked LT Spice and Electric (cmosedu) as the tutorial show (http://cmosedu.com/videos/electric/tutorial1/electric_tutorial_1.htm), but
when I try to simulate from Electric, it doesn't open LT Spice.
Any solution?
This is what I did. It works.
Setup parameters in electric-9.07.jar:
Run program: /Applications/LTspice.app/Contents/MacOS/script.sh
With args: ${FILENAME_NO_EXT} -r ${FILENAME_NO_EXT}.raw -o ${FILENAME_NO_EXT}.out
!!IMPORTANT!!
First argument isn't "-i ${FILENAME}". IT'S "${FILENAME_NO_EXT}".
I create "ELECTRIC" folder in Desktop and I use it for saving my *.spi files.
To allow the script to work, you must insert your libraries inside this folder on desktop (ELECTRIC).
SCRIPT
You need to create /Applications/LTspice.app/Contents/MacOS/script.sh
######START HERE######
#!/bin/bash
# Get argument from electric
args=("$#")
# Create *.net file for LTspice
cd ~/Desktop/ELECTRIC/
cp ${args[0]}.spi ${args[0]}.net
# Launch LTspice and pass it parameters.
cd /Applications/LTspice.app/Contents/MacOS/
./LTSpice ~/Desktop/ELECTRIC/${args[0]}.net ${args[1]} ~/Desktop/ELECTRIC/${args[2]} ${args[3]} ~/Desktop/ELECTRIC/${args[4]}
######END HERE######
It needs execution privileges:
sudo chmod +x /Applications/LTspice.app/Contents/MacOS/script.sh
Use Electric as tutorial says (http://cmosedu.com/videos/electric/tutorial1/electric_tutorial_1.htm).
It will open a small window with a netlist.
Click on run button to see the simulation.
To close LTspice, you must exit from it.
INFO:
If LTspice says you that you haven't its latest version, close the window and go on.
I'm trying to copy an image from Dockerhub to Bluemix registry by following the doc at https://new-console.eu-gb.bluemix.net/docs/containers/container_images_copying.html
I installed cf-cli and the IBM-Containers plugins on my Mac (OSX 10.11.6):
$ cf --version
cf version 6.21.0+dff2cf8-2016-07-27
$ cf plugins
Listing Installed Plugins...
OK
Plugin Name Version Command Name Command Help
IBM-Containers 0.8.897 ic IBM Containers plug-in
I've logged into my account:
$ cf login -a api.eu-gb.bluemix.net
API endpoint: api.eu-gb.bluemix.net
Email> andy#onthewings.net
Password>
Authenticating...
OK
Targeted org Haxe Foundation
Targeted space dev
API endpoint: https://api.eu-gb.bluemix.net (API version: 2.54.0)
User: andy#onthewings.net
Org: Haxe Foundation
Space: dev
$ cf ic login -a api.eu-gb.bluemix.net
$ cf ic info
Date/Time : 2016-08-22 08:43:39.352117576 +0800 HKT
Debug Mode : false
Host/URL : https://containers-api.eu-gb.bluemix.net
Registry Host : registry.eu-gb.bluemix.net
Bluemix API Host/URL : https://api.eu-gb.bluemix.net
Bluemix Org : Haxe Foundation(4a6547eb-37ae-4f41-9e7e-dcba87c99147)
Bluemix Space : dev(45d9dba9-068b-4918-82ff-1c2210a03dbc)
CLI Version : 0.8.897
However, when I try to copy an image, or to list the existing images, there is an error:
$ cf ic cpi gitlab/gitlab-ce:8.10.7-ce.0 registry.eu-gb.bluemix.net/gitlab-ce:8.10.7-ce.0
FAILED
The IBM Containers CLI must be initialized. Run "cf ic init" to initialize it.
$ cf ic images
FAILED
The IBM Containers CLI must be initialized. Run "cf ic init" to initialize it.
Any idea?
Oh, turn out I have to create a container registry namespace first. It can be done by trying to create a container in the web console. Select an existing image, say ibmliberty, and it will ask for creating a namespace for the current organisation.
After the namespace is created, run cf ic init, then the other commands will succeed as expected.