Does anyone know of a stand-alone way to upload an asset to an asset canister (such as a nice script that will call all of the asset canister batching and chunking functions automatically)? I’ve forked the asset canister and deployed it locally, and I’d love a simple way to upload files into it, but there’s no way that I know of to do that (so I’m writing my own script).
I’m hoping this work has already been done by somebody. Has it?
2 Likes
I want to add a npm package making this simple in JS, too
5 Likes
That would also be excellent
1 Like
That’s what I was going to do but I probably won’t now
1 Like
Can it be used locally? Do you know how that would be done? I passed it a local canister id and I get this error:
thread 'main' panicked at 'Could not create HTTP client.: reqwest::Error { kind: Builder, source: "Unknown TLS backend passed to `use_preconfigured_tls`" }', /home/lastmjs/.cargo/registry/src/github.com-1ecc6299db9ec823/ic-agent-0.10.0/src/agent/http_transport.rs:62:18
1 Like
If you’ve got the time and motivation to write it up, I’m happy to see if we could get you set up with a grant for it!
1 Like
lastmjs
December 4, 2021, 7:33pm
10
Ah thanks for the offer, I should really get back to the TypeScript, Python CDKs and Sudograph. I’m taking a slight detour for this: https://twitter.com/dominic_w/status/1467144071449915395
Checks a lot of boxes for me, Demergence has issues with streaming, easy to pick up too
lastmjs
December 4, 2021, 7:54pm
11
I got it to work by installing the main branch
I’ve been doing that with a little zsh script, but it sounds like you’re up and running!
2 Likes
Offer is still there? I would be interested to give it a go if I have some help
lastmjs
December 6, 2021, 3:15pm
14
I’m happy to off guidance if you need it too, @lastmjs on Telegram is best
Thanks I could definitely use some help.
I have a rough idea on where to start by calling the asset canister actor methods, but I have few questions:
1-What is the order of calling these methods or the order of the process? create_batch, commit_batch etc…
2- how do you authorize the actor from within the script? ‘dfx deploy’ do that automatically but I am not sure how to do that manually
I found how to authorize with your private key in here
return Secp256k1KeyIdentity.fromSecretKey(Buffer.from(privateKey, 'base64'));
};
(async () => {
try {
const canisterId = managerPrincipal();
const identity = initIdentity();
const agent = new HttpAgent({identity, fetch, host: 'https://ic0.app'});
const actor = Actor.createActor(idlFactory, {
agent,
canisterId
});
const buffer = readFileSync(`${process.cwd()}/.dfx/local/canisters/data/data.wasm`);
await actor.installCode([...new Uint8Array(buffer)], 'data');
} catch (e) {
console.error(e);
That was really helpful
mind sharing that @jorgenbuilder ?
For those running into the same issue (I got it from using ic-repl
), just make sure to update the Cargo.toml of the binary you’re trying to build like this:
-ic-agent = "0.9.0"
+ic-agent = { git = "https://github.com/dfinity/agent-rs" }
candid = { version = "0.7.8", features = ["random"] }
rustyline = "8.2"
rustyline-derive = "0.4"
ansi_term = "0.12"
pretty_assertions = "0.7"
terminal_size = "0.1"
codespan-reporting = "0.11"
pretty = "0.10.0"
pem = "0.8"
shellexpand = "2.1"
ic-agent = "0.9.0"
tokio = { version = "1.6.0", features = ["full"] }
garcon = "0.2.3"
anyhow = "1.0"
rand = "0.8"
logos = "0.12"
lalrpop-util = "0.19"
clap = "2.33"
structopt = "0.3.16"
ring = "0.16"
serde = "1.0"
2 Likes
I tested it and it works great for local development. Can this be used to upload assets to a canister deployed on mainnet too?
1 Like