Git Product home page Git Product logo

rust-web3's Introduction

web3

Ethereum JSON-RPC multi-transport client. Rust implementation of Web3.js library.

Build Status Crates.io

Documentation: crates.io

Status

Note this package is barely maintained and I am looking for an active maintainer (see #664). If you are starting a new project, I'd recommend choosing https://github.com/gakonst/ethers-rs instead.

Usage

First, add this to your Cargo.toml:

[dependencies]
web3 = "0.19.0"

Example

#[tokio::main]
async fn main() -> web3::Result<()> {
    let transport = web3::transports::Http::new("http://localhost:8545")?;
    let web3 = web3::Web3::new(transport);

    println!("Calling accounts.");
    let mut accounts = web3.eth().accounts().await?;
    println!("Accounts: {:?}", accounts);
    accounts.push("00a329c0648769a73afac7f9381e08fb43dbea72".parse().unwrap());

    println!("Calling balance.");
    for account in accounts {
        let balance = web3.eth().balance(account, None).await?;
        println!("Balance of {:?}: {}", account, balance);
    }

    Ok(())
}

If you want to deploy smart contracts you have written you can do something like this (make sure you have the solidity compiler installed):

solc -o build --bin --abi contracts/*.sol

The solidity compiler is generating the binary and abi code for the smart contracts in a directory called contracts and is being output to a directory called build.

For more see examples folder.

Futures migration

  • Get rid of parking_lot (replace with async-aware locks if really needed).
  • Consider getting rid of Unpin requirements. (#361)
  • WebSockets: TLS support (#360)
  • WebSockets: Reconnecting & Pings
  • Consider using tokio instead of async-std for ws.rs transport (issue with test).
  • Restore IPC Transport

General

  • More flexible API (accept Into<X>)
  • Contract calls (ABI encoding; debris/ethabi)
  • Batch Requests

Transports

  • HTTP transport
  • IPC transport
  • WebSockets transport

Types

  • Types for U256,H256,Address(H160)
  • Index type (numeric, encoded to hex)
  • Transaction type (Transaction from Parity)
  • Transaction receipt type (TransactionReceipt from Parity)
  • Block type (RichBlock from Parity)
  • Work type (Work from Parity)
  • Syncing type (SyncStats from Parity)

APIs

  • Eth: eth_*
  • Eth filters: eth_*
  • Eth pubsub: eth_*
  • net_*
  • web3_*
  • personal_*
  • traces_*

Parity-specific APIs

  • Parity read-only: parity_*

  • Parity accounts: parity_* (partially implemented)

  • Parity set: parity_*

  • signer_*

  • Own APIs (Extendable)

let web3 = Web3::new(transport);
web3.api::<CustomNamespace>().custom_method().wait().unwrap()

Installation on Windows

Currently, Windows does not support IPC, which is enabled in the library by default. To compile, you need to disable the IPC feature:

web3 = { version = "_", default-features = false, features = ["http"] }

Avoiding OpenSSL dependency

On Linux, native-tls is implemented using OpenSSL. To avoid that dependency for HTTPS or WSS use the corresponding features.

web3 = { version = "_", default-features = false, features = ["http-rustls-tls", "ws-rustls-tokio"] }

Note: To fully replicate the default features also add signing & ipc-tokio features.

Cargo Features

The library supports following features:

  • http - Enables HTTP transport (requires tokio runtime, because of hyper).
  • http-tls - Enables TLS support via reqwest/default-tls for HTTP transport (implies http; default).
  • http-native-tls - Enables TLS support via reqwest/native-tls for HTTP transport (implies http).
  • http-rustls-tls - Enables TLS support via reqwest/rustls-tls for HTTP transport (implies http).
  • ws-tokio - Enables WS transport using tokio runtime.
  • ws-tls-tokio - Enables TLS support for WS transport (implies ws-tokio; default).
  • ws-rustls-tokio - Enables rustls TLS support for WS transport (implies ws-tokio).
  • ws-async-std - Enables WS transport using async-std runtime.
  • ws-tls-async-std - Enables TLS support for WS transport (implies ws-async-std).
  • ipc-tokio - Enables IPC transport using tokio runtime (default).
  • signing - Enable account namespace and local-signing support (default).
  • eip-1193 - Enable EIP-1193 support.
  • wasm - Compile for WASM (make sure to disable default features).
  • arbitrary_precision - Enable arbitrary_precision in serde_json.
  • allow-missing-fields - Some response fields are mandatory in Ethereum but not present in EVM-compatible chains such as Celo and Fantom. This feature enables compatibility by setting a default value on those fields.

rust-web3's People

Contributors

akuanti avatar blanksteer avatar cperezz avatar debris avatar dependabot-preview[bot] avatar dependabot[bot] avatar e00e avatar elichai avatar elpiel avatar folex avatar fredfortier avatar fspmarshall avatar hcastano avatar insipx avatar leoyvens avatar lightyear15 avatar lsunsi avatar marmistrz avatar mdben1247 avatar mjkoo avatar nlordell avatar palango avatar r3v2d0g avatar rphmeier avatar sionois avatar svyatonik avatar tomusdrw avatar toxeus avatar usd-yamazaki avatar vorot93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-web3's Issues

Receipt should include status field

The current version of JSON RPC includes the following for eth_getTransactionReceipt

It also returns either :

root : DATA 32 bytes of post-transaction stateroot (pre Byzantium)
status: QUANTITY either 1 (success) or 0 (failure)

The Receipt struct does not include either of these fields.

Put original Solidity/other code in examples

Trying out the deployment of a contract, and everything is going smoothly except for the format of the bytecode/solidity contracts are supposed to be in. I'm getting many 'invalid data' and JSON parse errors for a simple 'greeter' contract.

I think it would help to include original solidity code, and maybe even a quick snippet with the process of compiling the solidity code to ABI + JSON with official solc compiler.

Dropping EventLoopHandle after running a request causes the program to hang.

Dropping EventLoopHandle before dropping Web3<T> causes a hang if at least one request has been issued. Example code:

extern crate web3;

use web3::futures::Future;

fn main() {
  let (eloop, http) = web3::transports::Http::new("http://localhost:8545").unwrap();
  let web3 = web3::Web3::new(http);
  let _accounts = web3.eth().accounts().wait().unwrap();

  drop(eloop);
}

This became an issue when I created a struct that owned both EventLoopHandle and Web3<T>. If my struct fields were in the wrong order, the program would hang when attempting to drop my struct. If I switched the order of the fields, the program would run to completion.

Cannot connect to client: Transport("SendError(\"...\")")

With the simple example below I get an error like Transport("SendError(\"...\")"). It worked in the beginning but then stopped working. Any idea what could cause that?

extern crate web3;

use web3::futures::Future;

fn main() {
    let (_, transport) = web3::transports::Http::new("http://localhost:8545").unwrap();
    let web3 = web3::Web3::new(transport);
    let accounts = web3.eth().accounts().wait().unwrap();

    println!("Accounts: {:#?}", accounts);
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Transport("SendError(\"...\")")', src/libcore/result.rs:906:4
stack backtrace:
   0:        0x10ed1fee3 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::h311e4a395df9fc90
   1:        0x10ed1c410 - std::sys_common::backtrace::_print::hebb60342f79f20b6
   2:        0x10ed21ce3 - std::panicking::default_hook::{{closure}}::h09124cef4c2cbbd0
   3:        0x10ed219e2 - std::panicking::default_hook::hfa171ff8edf516fa
   4:        0x10ed221f2 - std::panicking::rust_panic_with_hook::h3c41fb7cc19bbec2
   5:        0x10ed220d4 - std::panicking::begin_panic::he2991ed22bf2bf67
   6:        0x10ed21fa2 - std::panicking::begin_panic_fmt::hfd4bc5f2019d8a77
   7:        0x10ed21f0a - rust_begin_unwind
   8:        0x10ed58ec3 - core::panicking::panic_fmt::hae6752e5f963f9a5
   9:        0x10eaccb49 - core::result::unwrap_failed::h229ca956bb43bfce
  10:        0x10eacbb8b - <core::result::Result<T, E>>::unwrap::h317bd1e8f61b9bdc
  11:        0x10ead42d7 - raiden_rs::main::h50693c2b3a30536b
  12:        0x10ed2d66c - __rust_maybe_catch_panic
  13:        0x10ed226f8 - std::rt::lang_start::heab07b9c4d3b2654
  14:        0x10ead4434 - main

Not compiling on Windows, 1.24 nightly

Hi.
I'm getting this when trying to build example:

error[E0432]: unresolved import `self::tokio_uds::UnixStream`
  --> C:\Users\Andrey\.cargo\git\checkouts\rust-web3-ebc1a09fd5a9a2a2\c6bd1ab\src\transports\ipc.rs:10:5
   |
10 | use self::tokio_uds::UnixStream;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `UnixStream` in the root

error: aborting due to previous error

error: Could not compile `web3`.

Tried both gnu and msvc toolchains, cargo and github versions. Am I missing something?

How to convert U256 to stringified u64?

hey guys, probably a noob question. but i'd like to convert the U256 gotten from the balance function to a human readable number. I assume a string u64 is the only way to do this?

i tried using the low_u64 but i'm not even sure what that does, but the number it returns is wrong.

code 👇

extern crate web3;
use web3::*;
use types::{U256, Address};
use futures::{Future};

#[derive(Debug)]
struct Mapping {
	address: Address,
	balance: u64
}

impl Mapping {
	fn new (address: Address, balance: U256) -> Mapping {
		Mapping {
			address,
			balance: balance.low_u64()
		}
	}
}

fn main() {
	let (_eloop, transport) = web3::transports::Http::new("http://localhost:8545").unwrap();
	let web3 = web3::Web3::new(transport);
	let accounts = web3.eth().accounts().wait().unwrap();

	let balances: Vec<Mapping> = accounts.into_iter().fold(Vec::new(),|mut accum, address| {
		let balance = web3.eth().balance(address, None).wait();
		accum.push(Mapping::new(address, balance.unwrap()));
		accum
	});

	for balance in balances {
		println!("Balance : {:?}", balance)
	}
}
ganache-cli -e 30 -a 1
Ganache CLI v6.0.3 (ganache-core: 2.0.2)

Available Accounts
==================
(0) 0x6ce23c45eb5b818fdaf76944ba5dd5cf56990a83

Private Keys
==================
(0) 12059b88a7fd4db2e973e4c9670d344b119cd7f9b7f21324bf24245beb9eb4fc

HD Wallet
==================
Mnemonic:      image want animal chimney know dune age board world volcano great subway
Base HD Path:  m/44'/60'/0'/0/{account_index}

Listening on localhost:8545
eth_accounts
eth_getBalance
cargo run                                                                                                                                                                                    master ✚ ◼
   Compiling cryptobot v0.1.0 (file:///home/seunlanlege/Projects/cryptobot)
    Finished dev [unoptimized + debuginfo] target(s) in 2.97 secs
     Running `target/debug/cryptobot`
Balance : Mapping { address: 0x6ce23c45eb5b818fdaf76944ba5dd5cf56990a83, balance: 7766279631452241920 }


SealFields type

...with chain-specific types which are decodable from it: (e.g. an EthashSeal or a TendermintSeal).

Signing Transactions Offline

Support for signing transactions offline for sending to a locked node or potentially Infura would be extremely helpful. Similar functionality can be found in the ethereumjs-tx for javascript. Much of this functionality exists across the parity codebase and needs to be pieced together. In discussing this with @tomusdrw, the general steps required would be:

  1. Encode contract call (this can be done by ethabi)
  2. Create and fill a transaction request (nonce, gas, gasprice, etc) - I believe there is an RPC method to do that in Parity
  3. Encode the transaction into RLP
  4. Calculate hash and sign (this could be done by ethkey library)
  5. Broadcast signed transaction

Runtime Error with decoding value from query

I'm running into a strange runtime error with some fairly simple Solidity code:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error(Abi(Msg("Cannot decode uint256")), State { next_error: Some(Error(InvalidData, State { next_error: None, backtrace: None })), backtrace: None })', /checkout/src/libcore/result.rs:916:5

Using these dependencies:

web3 = "0.2.0"
ethereum-types = "0.2"

Solidity code for context:

  function makeDeposit() public payable returns (uint) {
    deposits[msg.sender] = deposits[msg.sender].add(msg.value);
    DepositMade(msg.sender, msg.value);
    return deposits[msg.sender];
  }

  function getDeposit(address who) constant public returns (uint) {
    return deposits[who];
  }

Rust code:

use std::env;
use std::fs::File;
use std::io::prelude::*;

extern crate serde_json;
use serde_json::{Value, Error};

extern crate ethereum_types;
use ethereum_types::{H160};

extern crate web3;
use web3::contract::{Contract, Options};
use web3::types::{Address, U256};

use web3::futures::Future;

use std::{thread, time};

fn read_json_file(filename: &str) -> Value {
  let file_path = format!("{}{}", env::current_dir().unwrap().display(), filename);
  let mut json_file = File::open(file_path).expect(&format!("{} not found", filename));
  let mut contents = String::new();
  json_file.read_to_string(&mut contents)
      .expect("something went wrong reading the file");
  let v: Value = serde_json::from_str(&contents).unwrap();
  v
}

fn main() {

  let (_eloop, transport) = web3::transports::Http::new("http://localhost:8545").unwrap();
  let web3 = web3::Web3::new(transport);
  let accounts = web3.eth().accounts().wait().unwrap();

  let _balance = web3.eth().balance(accounts[0], None).wait().unwrap();

  let addresses: Value = read_json_file("/addresses.json");

  let incentive_layer_address: H160 = H160::from_slice(addresses["incentiveLayer"].to_string().as_bytes());

  let incentive_layer_abi: &Value = &read_json_file("/../build/contracts/IncentiveLayer.json")["abi"];

  let il = serde_json::to_string(&incentive_layer_abi).unwrap();
  let incentive_layer_contract = Contract::from_json(web3.eth(), incentive_layer_address, il.as_bytes()).unwrap();

  incentive_layer_contract.call("makeDeposit", (), accounts[0], Options::with(|opt| opt.value = Some(1000.into())));

  let ten_millis = time::Duration::from_millis(2000);
  thread::sleep(ten_millis);

  let result = incentive_layer_contract.query("getDeposit", (accounts[0], ), None, Options::default(), None);

  //ERROR HERE!!!
  let balance: U256 = result.wait().unwrap();

  println!("{:?}", balance);

}

Generic approach to confirmations

More generic support for confirmations would be nice.

Currently we have a bunch of methods like "send_transaction_with_confirmations" instead it would be good to have a trait that can be implemented for some return types (e.g. futures resolving to transaction hashes) that allows you to (optionally) wait for confirmations.

Related: #86, #102, #89

Example showing how to deploy a new contract instance

Assuming that this is possible, an example showing how to deploy an instance of a new contract would be great. The example could assume that "solc" is installed on the system and shell out to it to compile the contract.

A zombie connection occurs with the filter.logs function.

This problem also occurs on both Windows and Ubuntu.
I am using the following crate.

I am making a server program using jsonrpc-http-server.
When there is a request from the client, the server accesses the parity and returns the acquired value.

When calling BaseFilter's logs function in the program,
If there are a large number of result logs, the connection with Parity will remain and will remain.
Finally, a "Too many open files" error occurs and you can not connect to Parity.

For example, this function works normally if the result is "Logs: 1"
If the result is "Logs: 13530", a zombie connection will occur.

fn get_logs(web3: &Web3<web3::transports::Http>) {
    let filter_build = FilterBuilder::default()
        .topics(None, Some(vec![H256::from("0x000000000000000000000000a6e345c5f3cc2801f4892b6a67a670d897303d0d")]), None, None)
        .from_block(BlockNumber::Number(0))
        .build();
    let filter = web3.eth_filter().create_logs_filter(filter_build).wait().unwrap();
    let result = filter.logs().wait().unwrap();

    println!("Logs: {:?}", result.len());
}

However, this problem only occurs when calling the logs function on jsonrpc-http-server, otherwise it does not occur.
I'm sorry if it is not a problem of rust-web3.

Issue with IPC transport?

I am very new to Rust, so there might be something that I'm overlooking; however, I was implementing some Parity-specific methods in a separate fork, and while benchmarking with criterion.rs, I noticed that method calls to parity_pendingTransactions stalled indefinitely over IPC. This method works 100% of the time with the http transport, so I am assuming the problem isn't with my implementation.

At first I thought it was due to the size of the RPC return (this was when there were around 15k+ pending), but that doesn't quite make sense, since a 20MB buffered transfer shouldn't be an issue over a unix socket.

This issue did make me recall a problem I was having a while back in Java/Scala. We have a microservice that would often stall when polling our Parity node via IPC with the Web3j Java client. We then re-wrote that service from the ground-up in Scala with our own IPC implementation, but still had the same issue. We then switched all calls to http and everything was fine.

So, considering that there might be an issue with IPC calls across three different implementations, in three different languages, and since you work on Parity as well, we wanted to solicit your advice on where you think the issue might reside?

P.S.: You mentioned in another post that you have no issues getting 20k calls/sec using the rust-web3 client. Would you mind sharing the hardware specs used to achieve that? Thanks!

Doesn't support TLS

The HTTP transport does not support TLS:

let (_eloop, transport) = web3::transports::Http::new("https://sokol.poa.network").unwrap();

leads to

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Transport("Io(Error { repr: Custom(Custom { kind: InvalidInput, error: NotHttp }) })")', src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

eth_getFilterChanges not working because of malformed id

Trying to capture events from a Smart Contract, I registered a Filter via EthFilter.create_logs_filter(...).
The rpc responded with the filter id "0x03" which is internally transformed to a "3" as the id of the BaseFilter struct.
So when the filter changes are queried, it tries to query filter "0x3" instead of "0x03", omitting the leading zero, which results in the rpc error: "FilterSubprovider - no filter with that id: 0x3".
It is possible to fix this by changing the BaseFilter id to type "String", but that might not be wanted.

This is the according output from ganache-cli:

# The library requests a new Filter:
eth_newFilter
   > {
   >   "jsonrpc": "2.0",
   >   "method": "eth_newFilter",
   >   "params": [
   >     {
   >       ...
   >     }
   >   ],
   >   "id": 1,
   >   "external": true
   > }
...
# Response containing the Filter ID 0x03:
 <   {
 <     "id": 1,
 <     "jsonrpc": "2.0",
 <     "result": "0x03"
 <   }
...
# Filter Changes fail because of wrong ID, always returning empty JSON Array in the end
eth_getFilterChanges
   > {
   >   "jsonrpc": "2.0",
   >   "method": "eth_getFilterChanges",
   >   "params": [
   >     "0x3"
   >   ],
   >   "id": 4,
   >   "external": true
   > }
FilterSubprovider - no filter with that id: 0x3
 <   {
 <     "id": 4,
 <     "jsonrpc": "2.0",
 <     "result": []
 <   }

Best regards,
hardliner93

InvalidOutputType("Expected single element, got a list")

The contract I'm querying returns a fixed array.

Result::unwrap()on anErr` value: Error(InvalidOutputType("Expected single element, got a list: [Bool(true), Uint(0x5ada606a), Uint(0x0)]")

I assume that is supported via the FixedArray macro? What signature, type definition has to be used for the query call to trigger/handle this?

Contract logs support

Seems that contracts can only query the blockchain or call methods.
There should be filter-like logs retrieval.

Need an example of how to wait for confirmations

I would like to be able to call a function on a contract, wait until the transaction is confirmed, and then do something with the result. I have a feeling this is relatively straight-forward, but the documentation isn't clear.

There is wait_for_confirmations and send_transaction_with_confirmation, but neither of these are part of the contract interface, and I'm not sure what I should be passing to these. A simple example would be much appreciated.

Contract deployment issue on a dev chain with 0 confirmation

While testing parity bridge with nightly version (ok with 1.9.5). The deployment of contract with rust-web3 is stuck on confirmation wait. I believe it might be related with instant sealing running before and no block creation afterward. This kind of modification let me run it : cheme@8af0f34

I think it is a corner case (dev and no confirmation), but I still open this issue for information.
For reference : paritytech/parity-bridge#151

Generate structs from contract interfaces

Example:

#[cfg(test)]
mod tests {
  use api;
  use helpers::tests::TestTransport;
  use types::U256;

  contract! {
    contract Token {
        event Transfer(address indexed from, address indexed to, uint256 value);
        event Approval(address indexed owner, address indexed spender, uint256 value);

        function balanceOf(address _owner) constant returns (uint256 balance);
        function transfer(address _to, uint256 _value) returns (bool success);
        function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
        function approve(address _spender, uint256 _value) returns (bool success);
        function allowance(address _owner, address _spender) constant returns (uint256 remaining);
    }
  }

  #[test]
  fn should_call_token_contract {
    // given
    let transport = helpers::tests::TestTransport::default();
    let eth = api::Eth::new(transport);
    let token = Token::at(1.into(), eth);

    // when
    let balance = token.balanceOf(5.into());

    // then
    assert_eq!(balance, U256::from(10));

  }
}

Documentation link does not match version on crates.io

The documentation link on crates.io points to the docs for version 0.2.0, but version 0.1.0 is currently the latest hosted version. The differences between the two versions are subtle enough that it isn't immediately obvious why things aren't working right if you try to use 0.1.0 based on the 0.2.0 docs.

I can not receive the values of "byte[64][]" returned by the contract.

It is the continuation of #47.
Thank you for the correspondence of #47.

When I tried it with the latest source, I can compile it, but I get an InvalidOutputType error.
I tried several while changing the type, but it did not work.

contract interface:

function getValues() public constant returns (uint[], byte[64][], address[])

rust source:

let result = contract.query("getValues", (), None, Options::default());
let a = result.wait();
match a {
    Ok(_) => {
        let (v1, v2, v3): (Vec<U256>, Vec<Vec<u8>>, Vec<Address>) = a.unwrap();
        println!("{:?} {:?} {:?}", v1, v2, v3);
    }
    Err(e) => println!("{:?}", e),
};

Try 1:

let (v1, v2, v3): (Vec<U256>, Vec<Vec<u8>>, Vec<Address>) = a.unwrap();
InvalidOutputType("Expected `bytes`, got FixedArray([FixedBytes([206]), FixedBytes([72]), FixedBytes([241]), FixedBytes([97]), FixedBytes([207]), FixedBytes([128]), FixedBytes([204]), FixedBytes([70]), FixedBytes([118]), FixedBytes([206]), FixedBytes([78]), FixedBytes([231]), FixedBytes([240]), FixedBytes([253]), FixedBytes([6]), FixedBytes([167]), FixedBytes([83]), FixedBytes([97]), FixedBytes([140]), FixedBytes([94]), FixedBytes([69]), FixedBytes([6]), FixedBytes([147]), FixedBytes([168]), FixedBytes([87]), FixedBytes([143]), FixedBytes([48]), FixedBytes([134]), FixedBytes([203]), FixedBytes([234]), FixedBytes([137]), FixedBytes([164]), FixedBytes([184]), FixedBytes([9]), FixedBytes([192]), FixedBytes([144]), FixedBytes([96]), FixedBytes([23]), FixedBytes([52]), FixedBytes([205]), FixedBytes([78]), FixedBytes([122]), FixedBytes([134]), FixedBytes([64]), FixedBytes([80]), FixedBytes([76]), FixedBytes([37]), FixedBytes([106]), FixedBytes([206]), FixedBytes([151]), FixedBytes([106]), FixedBytes([107]), FixedBytes([192]), FixedBytes([75]), FixedBytes([183]), FixedBytes([11]), FixedBytes([217]), FixedBytes([134]), FixedBytes([250]), FixedBytes([98]), FixedBytes([112]), FixedBytes([183]), FixedBytes([106]), FixedBytes([225])])")

Try 2:

let (v1, v2, v3): (Vec<U256>, Vec<Vec<H256>>, Vec<Address>) = a.unwrap();
InvalidOutputType("Expected `H256`, got [206]")

Try 3:

let (v1, v2, v3): (Vec<U256>, Vec<Vec<[H256; 1]>>, Vec<Address>) = a.unwrap();
InvalidOutputType("Expected `FixedArray(1)`, got FixedBytes([206])")

How can I receive the values?
Thank you.

Builder.execute() does not accept more than 5 parameters

Version: 0.1.0

I'm trying to deploy a contract that takes 14 parameters in its constructor, and I get the following compile error:

error[E0277]: the trait bound `(web3::types::H160, web3::types::H160, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256): web3::contract::tokens::Tokenizable` is not satisfied
   --> src/main.rs:292:10
    |
292 |         .execute(
    |          ^^^^^^^ the trait `web3::contract::tokens::Tokenizable` is not implemented for `(web3::types::H160, web3::types::H160, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256)`
    |
    = note: required because of the requirements on the impl of `web3::contract::tokens::Tokenize` for `(web3::types::H160, web3::types::H160, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256, web3::types::U256)`

I get a similar error for any more than 5 parameters. I suspect it's because the macro calls here only go up to 5: https://github.com/tomusdrw/rust-web3/blob/master/src/contract/tokens.rs#L88-L92

How do I get multiple return values from the contract function?

There is a function of such a contract.
function getValues() public constant returns (uint[], byte[64][], address[])

I wrote the Rust code to receive the value, but this is an error.

let result = contract.query("getValues", (), None, Options::default());
let values: Vec<Token> = result.wait().unwrap();
error[E0277]: the trait bound `std::vec::Vec<ethabi::Token>: web3::contract::tokens::Tokenizable` is not satisfied

It worked when you made changes to crate, but I think this is a bad way.

use ethabi::Token; -> use web3::contract::tokens::Token;

rust-web3/src/contract/tokens.rs:3
use ethabi::Token; -> pub use ethabi::Token;

ethabi/src/token/token.rs:7
#[derive(Debug, PartialEq, Clone)] -> #[derive(Debug, PartialEq, Clone, Deserialize)]

How is the best way to do it?
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.